Apply POM to InputRange
This commit is contained in:
parent
c4da04e4de
commit
9f8210bf75
|
|
@ -0,0 +1,42 @@
|
||||||
|
package pages.webelements;
|
||||||
|
|
||||||
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
|
||||||
|
public class InputRangePage
|
||||||
|
{
|
||||||
|
@FindBy(xpath = "//button[contains(text(),'Input Range')]")
|
||||||
|
private WebElement accordionItem;
|
||||||
|
|
||||||
|
@FindBy(id = "range-input")
|
||||||
|
private WebElement rangeInput;
|
||||||
|
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
public InputRangePage(WebDriver driver)
|
||||||
|
{
|
||||||
|
this.driver = driver;
|
||||||
|
PageFactory.initElements(this.driver, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clickOnAccordionItem()
|
||||||
|
{
|
||||||
|
accordionItem.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRangeInputValue(int value)
|
||||||
|
{
|
||||||
|
JavascriptExecutor js = (JavascriptExecutor) driver;
|
||||||
|
js.executeScript("arguments[0].value = arguments[1];", rangeInput, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragAndDropRangeInputBy(int x, int y)
|
||||||
|
{
|
||||||
|
Actions move = new Actions(driver);
|
||||||
|
move.dragAndDropBy(rangeInput, x, y).build().perform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package tests.webelements;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
|
||||||
|
import pages.webelements.InputRangePage;
|
||||||
|
|
||||||
|
public class InputRangeTests
|
||||||
|
{
|
||||||
|
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:
|
||||||
|
InputRangePage page = new InputRangePage(driver);
|
||||||
|
|
||||||
|
// Perform actions on the page:
|
||||||
|
page.clickOnAccordionItem();
|
||||||
|
page.setRangeInputValue(0);
|
||||||
|
page.dragAndDropRangeInputBy(100, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
// This is commented out so you can actually see what happened in the web page:
|
||||||
|
// driver.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue