How does your test automation code look like?
Does it look like this?
driver.get(homePageUrl); WebElement searchTextBox = browserDriver.findElement(By.id(searchTextBoxId)); searchTextBox.click(); searchTextBox.clear(); searchTextBox.sendKeys(keyword); WebElement searchTextButton = driver.findElement(By.id(searchTextButtonLocator)); searchTextButton.click(); assertTrue(driver.getTitle().equalsIgnoreCase(expectedResultsPageTitle)); assertTrue(driver.getCurrentUrl().equalsIgnoreCase(expectedResultsPageUrl)); WebElement resultCountLabel = browserDriver.findElement(By.xpath(resultCountLocator); String resultCountText = resultCountLabel.getText(); int startIndex = resultCountText.substring("of") + 3; int endIndex = resultCountText.substring(" items"); int resultCount = Integer.parseInt(resultCountText.substring(startIndex, endIndex); assertTrue(resultCount > 0);
or this?
HomePage homePage = new HomePage(driver); homePage.openPage(); homePage.searchForKeyword("java"); ResultsPage resultsPage = new ResultsPage(driver); assertTrue(resultsPage.isOpen() == true); assertTrue(resultsPage.resultCount() > 0);
If you can write the first version and want to modify it into the second, this step-by-step tutorial is for you.
The tutorial shows you everything you need to know for creating page objects.
The tutorial has 3 parts:
1. how to create page objects
2. how to create page elements
3. how to use page factory
When learning to create page objects, we will go through the following iterations:
1. PREPARE THE TEST CASE FOR AUTOMATION
1.1 group test case actions by page
1.2 break down test case actions in sub-actions
1.3 create methods and variables for each action and sub-action
2. CREATE THE TEST CLASS
2.1 Component of a test class
2.2 How a test script is executed
2.3 Create the template of the test class
2.4 Add code for setUpEnvironment() and cleanUpEnvironment() methods
2.5 Add the code for the test script
2.6 Create objects for the homePage and resultsPage
3. CREATE THE HOME PAGE CLASS
3.1 Create the template of the home page
3.2 Add the fields and methods to the class
3.3 Add values to the fields of the class
3.4 Add the WebDriver field and constructor to the class
3.5 Add the code for the methods
4. CREATE THE RESULTS PAGE CLASS
4.1 Create the template of the results page
4.2 Add the fields and methods to the class
4.3 Add values to the fields of the class
4.4 Add the WebDriver field and constructor to the class
4.5 Add the code for the methods
Want to get started?
Transfer USD 25 through Paypal to alex@alexsiminiuc.com today.
You get the 3-part tutorial and unlimited email support.
0 Comment to "Learn Page Objects in 3 Easy Lessons"
Post a Comment