Selenium (11 Part Series)
1 Selenium Java Cheat Sheet
2 Selenium Java Dropdowns, Checkboxes, Calendar, Autocomplete
… 7 more parts…
3 Getting started with TestNG Java Framework
4 Selenium Java: Handle Alerts & Popups, IFrames, Switch Windows
5 Selenium Java (Implicit & Explicit) Waits
6 Selenium – Design a Framework: Page Object Pattern
7 Cucumber BDD Framework
8 Building a Selenium Framework
9 Selenium Testautomation on Windows Desctop App with Winium (Java)
10 Alternatives: Actions-Class and Javascript Executer in Selenium
11 Selenium Page Factory
Which Framework to use?
How to write scripts, store objects in a effective way?:
Frameworks:
data-driven, keyword-driven & Page Object Pattern
Why POP?
- easy to maintain
- easy readability of scripts
- reduce of eliminate duplicacy
- re-usability of code
- reliability
Basics of Page Object Pattern
PageObjects Class
Create Class for each Page:
Homepage – all Objects belonging to homepage
Login – JavaClass(LoginPage)
to identify the objects on one page
public class MaerkischeScholle {
WebDriver driver;
//local driver
public MaerkischeScholle(WebDriver driver) {
this.driver = driver;
//driver from where parameter is passed into constructor, is passed to local driver
}
By textFlatAvailability = By.xpath("//*[@id='article-27']");
public WebElement TextFlat() {
return driver.findElement(textFlatAvailability);
}
}
Enter fullscreen mode Exit fullscreen mode
Testcase Class
Create a Class for Testcases
eg. Login
call Login-Field from Loginpage-Class
than you can act on the Login-Field
or get a Text from a Page and print it
package testcases;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import objectrepository.MaerkischeScholle;
public class CheckAvailability {
@Test
public void CheckText() {
System.setProperty("webdriver.gecko.driver", "//home//helloworld//Documents//Code//Drivers" +
"//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.maerkische-scholle.de");
MaerkischeScholle ms = new MaerkischeScholle(driver);
String text = ms.TextFlat().getText();
System.out.println(text);
}
}
Enter fullscreen mode Exit fullscreen mode
Driver
The Webdriver is initiated in the Testcase Class
System.setProperty("webdriver.gecko.driver", "//home//helloworld//Documents//Code//Drivers" +
"//geckodriver");
WebDriver driver = new FirefoxDriver();
Enter fullscreen mode Exit fullscreen mode
Testcases Class (parameter for new object of PageObjectClass)
MaerkischeScholle ms = new MaerkischeScholle(driver);
Enter fullscreen mode Exit fullscreen mode
and then passed to the PageObjects-Class as a parameter through the constructor.
-> PageObjectsclass
WebDriver driver;
//local driver
public MaerkischeScholle(WebDriver driver) {
this.driver = driver;
//driver from where parameter is passed into constructor, is passed to local driver
PageFactory.initElements(driver, this);
// to use the @FindBy Annotation
}
Enter fullscreen mode Exit fullscreen mode
if you switch to another page, just create a new PageObjekt in the Testcases Class and pass the driver
HomePage hp = new HomePage(driver);
Enter fullscreen mode Exit fullscreen mode
PageObjectFactory @FindBy
@FindBy(xpath= "//*[@id='article-27']")
WebElement textFlatAvailability;
public WebElement TextFlat() {
return textFlatAvailability;
}
Enter fullscreen mode Exit fullscreen mode
Selenium (11 Part Series)
1 Selenium Java Cheat Sheet
2 Selenium Java Dropdowns, Checkboxes, Calendar, Autocomplete
… 7 more parts…
3 Getting started with TestNG Java Framework
4 Selenium Java: Handle Alerts & Popups, IFrames, Switch Windows
5 Selenium Java (Implicit & Explicit) Waits
6 Selenium – Design a Framework: Page Object Pattern
7 Cucumber BDD Framework
8 Building a Selenium Framework
9 Selenium Testautomation on Windows Desctop App with Winium (Java)
10 Alternatives: Actions-Class and Javascript Executer in Selenium
11 Selenium Page Factory
暂无评论内容