diff --git a/src/pages/webelements/InputsWithUIDialogsPage.java b/src/pages/webelements/InputsWithUIDialogsPage.java new file mode 100644 index 0000000..89f76d4 --- /dev/null +++ b/src/pages/webelements/InputsWithUIDialogsPage.java @@ -0,0 +1,43 @@ +package pages.webelements; + +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +public class InputsWithUIDialogsPage +{ + @FindBy(xpath = "//button[contains(text(),'Inputs With UI Dialogs')]") + private WebElement accordionItem; + + @FindBy(id = "color-input") + private WebElement colorInput; + + @FindBy(id = "file-input") + private WebElement fileInput; + + private WebDriver driver = null; + + public InputsWithUIDialogsPage(WebDriver driver) + { + this.driver = driver; + PageFactory.initElements(this.driver, this); + } + + public void clickOnAccordionItem() + { + accordionItem.click(); + } + + public void setColor(String color) + { + JavascriptExecutor js = (JavascriptExecutor) driver; + js.executeScript("arguments[0].value = arguments[1];", colorInput, color); + } + + public void setFile(String text) + { + fileInput.sendKeys(text); + } +} diff --git a/src/tests/webelements/InputsWithUIDialogsTests.java b/src/tests/webelements/InputsWithUIDialogsTests.java new file mode 100644 index 0000000..c868385 --- /dev/null +++ b/src/tests/webelements/InputsWithUIDialogsTests.java @@ -0,0 +1,33 @@ +package tests.webelements; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +import pages.webelements.InputsWithUIDialogsPage; + +public class InputsWithUIDialogsTests +{ + public static void main(String[] args) + { + // Specify path to WebDriver: + System.setProperty("webdriver.gecko.driver", "/snap/bin/geckodriver"); + + // Launch browser and navigate to test page: + WebDriver driver = new FirefoxDriver(); + driver.manage().window().maximize(); + driver.get("https://ramoncaballero.dev/sdet/selenium-webdriver/playgrounds/"); + + // Instantiate the page model: + InputsWithUIDialogsPage page = new InputsWithUIDialogsPage(driver); + + // Perform actions on the page: + page.clickOnAccordionItem(); + page.setColor("#FF0000"); + page.setFile("/home/mon/empty.txt"); + + // + + // This is commented out so you can actually see what happened in the web page: + // driver.quit(); + } +} diff --git a/src/webelements/InputsWithUIDialogs.java b/src/webelements/InputsWithUIDialogs.java deleted file mode 100644 index dc7250f..0000000 --- a/src/webelements/InputsWithUIDialogs.java +++ /dev/null @@ -1,37 +0,0 @@ -package webelements; - -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; - -public class InputsWithUIDialogs -{ - public static void main(String[] args) - { - // Specify path to WebDriver: - System.setProperty("webdriver.gecko.driver", "/snap/bin/geckodriver"); - - // Launch browser and navigate to test page: - WebDriver driver = new FirefoxDriver(); - driver.manage().window().maximize(); - driver.get("https://ramoncaballero.dev/sdet/selenium-webdriver/playgrounds/"); - - // Click on the 'Inputs With UI Dialogs' accordion item: - driver.findElement(By.xpath("//button[contains(text(),'Inputs With UI Dialogs')]")).click(); - - // Color input: - JavascriptExecutor js = (JavascriptExecutor) driver; - js.executeScript("document.getElementById('color-input').value = '#000000';"); - - // File input: - WebElement fileInput = driver.findElement(By.id("file-input")); - fileInput.sendKeys("/etc/legal"); - - // - - // This is commented out so you can actually see what happened in the web page: - // driver.quit(); - } -}