Apply POM to InputsWithUIDialogs
This commit is contained in:
parent
7d4096225a
commit
92d6619c5e
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue