Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. public class Products {
  2.  
  3.     public void open() {
  4.         Selenide.open("/");
  5.     }
  6.  
  7.     public void add(String name) {
  8.         $("#btn-add-product").click();
  9.         new Dialog()
  10.                 .setFor("Name:", name)
  11.                 .setFor("Path:", name)
  12.                 .submit();
  13.         new ConfirmationDialog().confirm();
  14.     }
  15. }
  16.  
  17. //
  18.  
  19. public class Dialog {
  20.  
  21.     private SelenideElement container = $(".ui-dialog");
  22.  
  23.  
  24.     public Dialog setFor(String label, String value) {
  25.         new DialogInput(this.container, label).setValue(value);
  26.         return this;
  27.     }
  28.  
  29.     public void submit() {
  30.         this.container.find("[id^=dialog-btn]").click();
  31.     }
  32. }
  33.  
  34. //
  35.  
  36. public class DialogInput {
  37.  
  38.     private final SelenideElement parent;
  39.     private final String label;
  40.  
  41.     public DialogInput(SelenideElement parent, String label) {
  42.         this.parent = parent;
  43.         this.label = label;
  44.     }
  45.  
  46.     private SelenideElement element() {
  47.         return this.parent.find(withText(label)).parent().find("input");
  48.  
  49.     }
  50.  
  51.     public void setValue(String value) {
  52.         element().val(value);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement