org.openqa.selenium.support.PageFactory Java Examples

The following examples show how to use org.openqa.selenium.support.PageFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WordPressBlogTestsWithPageObject.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
@Test (dependsOnMethods = "testEditPost")
public void testDeletePost() {
    AdminLoginPage loginPage =
            PageFactory.initElements(driver, AdminLoginPage.class);
    AllPostsPage allPostsPage = loginPage.login(username, password);
    allPostsPage.deleteAPost("Editing Post using PageObjects");
}
 
Example #2
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
void dashboardPage_showsModuleCount() {
    driver.get(testUrl()+"/dashboard");

    var page = new DashboardPage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
    page.waitForPageLoaded();

    assertEquals(3, page.modulesCount());
    assertEquals(1, page.stacksCount());
    assertEquals(0, page.stacksToUpdateCount());

    percy.snapshot("Dashboard");
}
 
Example #3
Source File: WordPressBlogTestsWithPageObject.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 5 votes vote down vote up
@Test
public void testCountPost() {
    AdminLoginPage loginPage =
            PageFactory.initElements(driver, AdminLoginPage.class);
    AllPostsPage allPostsPage = loginPage.login(username, password);
    Assert.assertEquals(allPostsPage.getAllPostsCount(), 1);
}
 
Example #4
Source File: WordPressBlogTestsWithPageObject.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 5 votes vote down vote up
@Test
public void testEditPost() {
    AdminLoginPage loginPage =
            PageFactory.initElements(driver, AdminLoginPage.class);
    AllPostsPage allPostsPage = loginPage.login(username, password);
    allPostsPage.editAPost("Creating New Post using PageObjects",
            "Editing Post using PageObjects", "Test framework low maintenance");
}
 
Example #5
Source File: WordPressBlogTestsWithPageObject.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 5 votes vote down vote up
@Test
public void testAddNewPost() {
    AdminLoginPage loginPage =
            PageFactory.initElements(driver, AdminLoginPage.class);
    AllPostsPage allPostsPage = loginPage.login(username, password);
    allPostsPage.createANewPost("Creating New Post using PageObjects",
            "Its good to use PageObjects");
}
 
Example #6
Source File: AllPostsPage.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 5 votes vote down vote up
public void editAPost(String presentTitle, String newTitle,
                      String description) {
    goToParticularPostPage(presentTitle);
    EditPostPage editPost = PageFactory.initElements(driver,
            EditPostPage.class);
    editPost.editPost(newTitle, description);
}
 
Example #7
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
@Order(1) // this test runs first as it logs the user in !
void loginPage() {
    driver.get(testUrl());
    driver.manage().window().setSize(new Dimension(1280,800));

    var page = new LoginPage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

    percy.snapshot("Login Page");

    page.login("admin", "admin123");
}
 
Example #8
Source File: SeleniumApplicationTest.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Test
public void navigate() {
	driver.get("http://localhost:8080/p1.php");
	Page1 pg1 = PageFactory.initElements(driver, Page1.class);
	Assert.assertEquals(pg1.title(), "Page 1");
	By id = By.id("p2-link");
	WebElement element = this.driver.findElement(id);
	Assert.assertEquals(element.getText(), "Go To Page 2");
	element.click();

	Page2 pg2 = PageFactory.initElements(driver, Page2.class);
	WebElement message = pg2.message();
	Assert.assertEquals(message.getText(), "Welcome!");
}
 
Example #9
Source File: FindByAnnotationTest.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
private void test(String pageName, Function<GooglePage, WebElement> elementGetter) {
    driver.get("http://www.google.com/");
    GooglePage page = PageFactory.initElements(driver, GooglePage.class);
    WebElement inputElement = elementGetter.apply(page);
    // annotation-driven element is lazy, need to do something with it
    inputElement.sendKeys("search");
    PageAwareBy locator = PageAwareBy.by(pageName, By.name("q"));
    Scored<By> newLocation = driver.getCurrentEngine().findNewLocations(locator, driver.getPageSource()).get(0);
    Assertions.assertEquals(inputElement, driver.findElement(newLocation.getValue()));
}
 
Example #10
Source File: CartPagePageFactory.java    From qashowcase with GNU General Public License v3.0 5 votes vote down vote up
public CartPagePageFactory(WebDriver driver) {
    this.driver = driver;
    this.driverWait = new WebDriverWait(driver, ScriptBase.DEFAULT_WEB_DRIVER_WAIT);
    this.driverJSExecutor = (JavascriptExecutor) driver;

    PageFactory.initElements(driver, this);
}
 
Example #11
Source File: LoginPagePageFactory.java    From qashowcase with GNU General Public License v3.0 5 votes vote down vote up
public LoginPagePageFactory(WebDriver driver) {
    this.driver = driver;
    this.driverWait = new WebDriverWait(driver, ScriptBase.DEFAULT_WEB_DRIVER_WAIT);
    this.driverJSExecutor = (JavascriptExecutor) driver;

    PageFactory.initElements(driver, this);
}
 
Example #12
Source File: HomePagePageFactory.java    From qashowcase with GNU General Public License v3.0 5 votes vote down vote up
public HomePagePageFactory(WebDriver driver) {
    this.driver = driver;
    this.driverWait = new WebDriverWait(driver, ScriptBase.DEFAULT_WEB_DRIVER_WAIT);
    this.driverJSExecutor = (JavascriptExecutor) driver;

    PageFactory.initElements(driver, this);
}
 
Example #13
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
void jobPage_showsJobDetails() {
    driver.get(testUrl()+"/stacks/de28a01f-257a-448d-8e1b-00e4e3a41db2/jobs/5e856dc7-6bed-465f-abf1-02980206ab2a");

    var page = new JobPage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

    assertThat(page.jobDetailTitle()).isEqualTo("Job 5e856dc7-6bed-465f-abf1-02980206ab2a");

    percy.snapshot("Job Details");
}
 
Example #14
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
void stackPage_showsStackDetails() {
    driver.get(testUrl()+"/stacks/de28a01f-257a-448d-8e1b-00e4e3a41db2/edit");

    var page = new StackPage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

    assertThat(page.stackName()).isEqualTo("local-mongo");

    percy.snapshot("Stack Details");
}
 
Example #15
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
void modulePage_showsModuleDetails() {
    driver.get(testUrl()+"/modules/e01f9925-a559-45a2-8a55-f93dc434c676");

    var page = new ModulePage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

    assertThat(page.moduleName()).isEqualTo("terraform-docker-mongo");
    assertThat(page.moduleDescription()).contains("A sample terraform");
    assertThat(page.terraformImageTag()).isEqualTo("0.11.14");

    percy.snapshot("Module Details");
}
 
Example #16
Source File: SeleniumIT.java    From gaia with Mozilla Public License 2.0 5 votes vote down vote up
@Test
void modulesPage_showsModules() {
    driver.get(testUrl()+"/modules");

    var page = new ModulesPage(driver);
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
    page.waitForPageLoaded();

    assertEquals(3, page.modulesCount());

    percy.snapshot("Modules");
}
 
Example #17
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static <T> T to(WebDriver driver, Class<T> page) {
	driver.get("http://localhost:8080/");
	return (T) PageFactory.initElements(driver, page);
}
 
Example #18
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static <T> T to(WebDriver driver, Class<T> page) {
	driver.get("http://localhost:8080/");
	return (T) PageFactory.initElements(driver, page);
}
 
Example #19
Source File: LogoutPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static LogoutPage to(WebDriver driver) {
	driver.get("http://localhost:8080/logout");
	return PageFactory.initElements(driver, LogoutPage.class);
}
 
Example #20
Source File: LoginPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public <T> T login(Class<T> page) {
	this.button.click();
	return PageFactory.initElements(LoginPage.this.driver, page);
}
 
Example #21
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static <T> T to(WebDriver driver, Class<T> page) {
	driver.get("http://localhost:8080/");
	return (T) PageFactory.initElements(driver, page);
}
 
Example #22
Source File: LoginPageStep3.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 4 votes vote down vote up
public LoginPageStep3() throws Exception {
    PageFactory.initElements(DriverBase.getDriver(), this);
}
 
Example #23
Source File: LogoutPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public LoginPage logout() {
	this.logout.click();
	return PageFactory.initElements(this.driver, LoginPage.class);
}
 
Example #24
Source File: LogoutPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static LogoutPage to(WebDriver driver) {
	driver.get("http://localhost:8080/logout");
	return PageFactory.initElements(driver, LogoutPage.class);
}
 
Example #25
Source File: LogoutPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public LoginPage logout() {
	this.logout.click();
	return PageFactory.initElements(this.driver, LoginPage.class);
}
 
Example #26
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public IndexPage(WebDriver webDriver) {
	this.driver = webDriver;
	PageFactory.initElements(webDriver, this);
}
 
Example #27
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public static <T> T to(WebDriver driver, Class<T> page) {
	driver.get("http://localhost:8080/");
	return (T) PageFactory.initElements(driver, page);
}
 
Example #28
Source File: GuineaPigPage.java    From demo-java with MIT License 4 votes vote down vote up
public GuineaPigPage(WebDriver driver) {
    this.driver = driver;
    PageFactory.initElements(driver, this);
}
 
Example #29
Source File: IndexPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public IndexPage(WebDriver webDriver) {
	this.driver = webDriver;
	PageFactory.initElements(webDriver, this);
}
 
Example #30
Source File: LoginPage.java    From Spring with Apache License 2.0 4 votes vote down vote up
public Form(SearchContext context) {
	PageFactory.initElements(new DefaultElementLocatorFactory(context), this);
}