Wednesday, 22 February 2017

Update the page class files.

For page classes, we have already defined the package & also added the class files for each page.
Let’s test with some basic data like printing the data in methods. Let’s take an example of SignInTest.
As previously mentioned, to sign in we need to lunch the browser > navigate to sign in page > insert valid details & click on signin button > It should navigate to MyAccountPage.
Download the java files from here. & follow the below steps:

  •  Extract the .zip file.
  •  Replace the SignInTest.java file inside “com.demo.pom.pages” package.
  • Replace SignInPage.java & LunchPage.java file inside “com.demo.pom.pages” package.
Code Overview:
            LunchPage.java

    • Is used to initialize the web browser instance. To initialize the browser instance let’s create a method known as openURL.
    • From Home Page, click on SignIn Link to navigate to SignIn page. So, create a method gotoSignInPage which will create the object of sign page & will return the same.
            SignInPage.java

    • Create a method doLogin & write the code for login.
    • If the login success it should return the object of MyAccountPage.
            SignInTest.java

    •  This is the test class file, here we will add the @Test annotation which will be used to run the test.
    • 1st we are creating the Object of Lunch Page. Using the object of Lunch Page, we are calling the methods inside it.
    •  Create the Object of Sign In page & call the doLogin Method inside it.
After replacing all three files, Right Click on SignInTest.java file > Click on Run As > Test NG Test.
Verify the below result:
It should print the messages inside each method & testng result should show Pass.

If you are seeing the test case as pass, then we ready to go ahead. But there are few challenges in this step. Please check the below listed challenges:
  1. Suppose in SignTest.java we are creating the object of WebDriver (known as driver), then the same driver must be shared across all page classes.
  2.  Adding common methods.

To overcome these challenges please check the next post. 


<<<Prev       Next>>>

No comments:

Post a Comment