Product Selection Action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
package appModules;
import pageObjects.Home_Page;
import pageObjects.ProductListing_Page;
import utility.Constant;
import utility.ExcelUtils;
import utility.Log;
// This is called Modularization, when we club series of actions in to one Module
// For Modular Driven Framework, please see
//http://www.toolsqa.com/selenium-webdriver/modular-driven/ public class ProductSelect_Action { // iTestcaseRow is the row number of our Testcase name in the Test Data sheet // iTestcaseRow is passed as an Argument to this method, //so that it can used inside this method // For use of Functions & Parameters, please see //http://www.toolsqa.com/selenium-webdriver/function-parameters/ public static void productType(int iTestCaseRow) throws Exception{ try{ // iTestcaseRow is the row number of our Testcase name in the //Test Data sheet // Constant.Col_ProductType is the column number for Product //Type column in the Test Data sheet // Please see the Constant class in the Utility Package // For Use of Constant Variables, please see //http://www.toolsqa.com/selenium-webdriver/constant-variables/ // If condition will check that if the Excel value for the //Product Type is Accessories, then do this if("Accessories".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductType))){ // Selecting the link Accessories from Home Page under Top //Navigation // This is call Page Object Model (POM) // For use of POM, please see //http://www.toolsqa.com/selenium-webdriver/page-object-model/ Home_Page.TopNavigation.Product_Type.Accessories(); // Printing the logs Log.info("Product Type Accessories is selected from the Top menu"); } // If the Excel value for the Product Type is iMacs, then do this if("iMacs".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductType))){ Home_Page.TopNavigation.Product_Type.iMacs(); Log.info("Product Type iMacs is selected from the Top menu"); } // If the Excel value for the Product Type is iPads, then do this if("iPads".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductType))){ Home_Page.TopNavigation.Product_Type.iPads(); Log.info("Product Type iPads is selected from the Top menu"); } // If the Excel value for the Product Type is iPhones, then do this if("iPhones".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductType))){ Home_Page.TopNavigation.Product_Type.iPhones(); Log.info("Product Type iPhones is selected from the Top menu"); } // If the Excel value for the Product Type is null, then do this if("".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductType))){ Log.warn("Excel value for Product Type is Blank"); } // Every exception thrown from any class or method, //will be catch here and will be taken care off // For Exception handling please see //http://www.toolsqa.com/selenium-webdriver/exception-handling-selenium-webdriver/ }catch(Exception e){ // Here I have used this as just for the sake of an example // I am just catching the Exception and again throwing it // back to the Main testcase, without handling it // You may like to print some information here, in case of exception throw(e); } } // iTestcaseRow is the row number of our Testcase name in the Test Data sheet // iTestcaseRow is passed as an Argument to this method, //so that it can used inside this method // For use of Functions & Parameters, please see // http://www.toolsqa.com/selenium-webdriver/function-parameters/ public static void productNumber(int iTestCaseRow) throws Exception{ try{ // iTestcaseRow is the row number of our Testcase name in the //Test Data sheet // Constant.Col_ProductNumber is the column number for Product //Number column in the Test Data sheet // Please see the Constant class in the Utility Package // For Use of Constant Variables, please see //http://www.toolsqa.com/selenium-webdriver/constant-variables/ // If condition will check that if the Excel value for the // Product Number is "Product 1", then do this if("Product 1".equals(ExcelUtils.getCellData(iTestCaseRow, //Constant.Col_ProductNumber))){ // Clicking on the Add to Cart button for the Product 1 // This is call Page Object Model (POM) // For use of POM, please see //http://www.toolsqa.com/selenium-webdriver/page-object-model/ ProductListing_Page.Product_1.btn_AddToCart().click(); // Printing logs for the performed action Log.info("Product 1 is selected from the Product listing page"); } // If the Excel value for the Product Number is "Product 2", //then do this if("Product 2".equals(ExcelUtils.getCellData(iTestCaseRow, //Constant.Col_ProductNumber))){ ProductListing_Page.Product_2.btn_AddToCart().click(); Log.info("Product 2 is selected from the Product listing page"); } /// If the Excel value for the Product Type is null, then do this if("".equals(ExcelUtils.getCellData(iTestCaseRow, Constant.Col_ProductNumber))){ Log.warn("Excel value for Product Number is Blank"); } // Clicking on the "Go to Cart" button on the Pop Up Box ProductListing_Page.PopUpAddToCart.btn_GoToCart().click(); // Every exception thrown from any class or method, //will be catch here and will be taken care off // For Exception handling please see //http://www.toolsqa.com/selenium-webdriver/exception-handling-selenium-webdriver/ }catch(Exception e){ // Here I have used this as just for the sake of an example // I am just catching the Exception and again throwing it back to //the Main testcase, without handling it // You may like to print some information here, in case of exception throw(e); } } } |
Check Out Action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package appModules;
import org.testng.Reporter;
import pageObjects.BaseClass;
import pageObjects.CheckOut_Page;
// This is called Modularization, when we club series of actions in to one Module
// For Modular Driven Framework, please see
//http://www.toolsqa.com/selenium-webdriver/modular-driven/ public class CheckOut_Action { // I could have created a Function for it but I keep calculations in //Functions and test steps in Module Actions // It could have been avoided and simply put these steps in Test Case, // it depends totally on you, everybody has their own choice public static void Execute() throws Exception{ // This is to get the Product name on the Check Out page with using //getText() method // CheckOut_Page.sProductName is a static variable and can be used // anywhere with its class name // Once some text is stored in this variable can be used later in //any other class CheckOut_Page.sProductName=CheckOut_Page.txt_ProductName().getText(); // This is all about Verification checks, these does not stop your //execution but simply report fail at the end // This is to check that if the value in the variable sProductName //is not null, then do this if(!"".equals(CheckOut_Page.sProductName)){ // Here I have put a verification check on the Product Name, //if it is displayed my verification will pass Reporter.log("Verification Passed for Product Name on Check Out page."); }else{ // If it not displayed then the verification check is failed Reporter.log("Verification Failed for Product Name on Check Out page."); // If the above verification gets failed then I have to report this //to my test and fail the test accordingly // To achieve this, I have initialized this variable of Base class at //the start of my test with value true in it // At the end of my test, i will match the value, if it will be false //then I will fail the test, else the test will be pass BaseClass.bResult=false; } CheckOut_Page.sProductPrice= CheckOut_Page.txt_ProductPrice().getText(); if(!"".equals(CheckOut_Page.sProductPrice)){ Reporter.log("Verification Passed for Product Price on Check Out page."); }else{ Reporter.log("Verification Failed for Product Price on Check Out page."); BaseClass.bResult=false; } // Clicking on the Continue button on the Check Out page CheckOut_Page.btn_Continue().click(); } } |
Payment Details Action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package appModules;
import org.testng.Reporter;
import pageObjects.PaymentDetails_Page;
import utility.Constant;
import utility.ExcelUtils;
import utility.Log;
// This is called Modularization, when we club series of actions in to one Module
// For Modular Driven Framework, please see
//http://www.toolsqa.com/selenium-webdriver/modular-driven/ public class PaymentDetails_Action { // iTestcaseRow is the row number of our Testcase name in the Test Data sheet // iTestcaseRow is passed as an Argument to this method, //so that it can used inside this method // For use of Functions & Parameters, please see //http://www.toolsqa.com/selenium-webdriver/function-parameters/ public static void execute(int iTestCaseRow) throws Exception{ try{ // Storing the Email in to a String variable and Getting the //Email address from Test Data Excel sheet // iTestcaseRow is the row number of our Testcase name in the //Test Data sheet // Constant.Col_Email is the column number for Email column in the //Test Data sheet // Please see the Constant class in the Utility Package // For Use of Constant Variables, please see //http://www.toolsqa.com/selenium-webdriver/constant-variables/ String sEmail = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_Email); // Clearing the pre-populated details on this field PaymentDetails_Page.txt_Email().clear(); // Here we are sending the Email string to the Email Textbox on //the Payment Detail Page // This is call Page Object Model (POM) // For use of POM, please see //http://www.toolsqa.com/selenium-webdriver/page-object-model/ PaymentDetails_Page.txt_Email().sendKeys(sEmail); // Printing the logs for what we have just performed Log.info(sEmail +" is entered as First Name on the Payment detail page"); String sFirstName = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_FirstName); PaymentDetails_Page.txt_FirstName().clear(); PaymentDetails_Page.txt_FirstName().sendKeys(sFirstName); Log.info(sFirstName +" is entered as First Name on the Payment detail page"); String sLastName = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_LastName); PaymentDetails_Page.txt_LastName().clear(); PaymentDetails_Page.txt_LastName().sendKeys(sLastName); Log.info(sLastName +" is entered as Last Name on the Payment detail page"); String sAddress = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_Address); PaymentDetails_Page.txt_Address().clear(); PaymentDetails_Page.txt_Address().sendKeys(sAddress); Log.info(sAddress +" is entered as Address on the Payment detail page"); String sCity = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_City); PaymentDetails_Page.txt_City().clear(); PaymentDetails_Page.txt_City().sendKeys(sCity); Log.info(sCity +" is entered as City on the Payment detail page"); String sCountry = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_Country); PaymentDetails_Page.drpdwn_Country(sCountry); Log.info(sCountry +" is Selected as Country on the Payment detail page"); String sPhone = ExcelUtils.getCellData(iTestCaseRow, Constant.Col_Phone); PaymentDetails_Page.txt_Phone().clear(); PaymentDetails_Page.txt_Phone().sendKeys(sPhone); Log.info(sPhone +" is entered as Phone on the Payment detail page"); // This is to check that if the Check box for //"Same as Billing address" is not already checked if(!PaymentDetails_Page.chkbx_SameAsBillingAdd().isSelected()){ // It it is unchecked, then check the check box PaymentDetails_Page.chkbx_SameAsBillingAdd().click(); Log.info("Same as Billing address check box is selected on //the Payment detail page"); } // Clicking on the Purchase button to complete the payment PaymentDetails_Page.btn_Purchase().click(); Log.info("Click action is performed on Purchase button on the //Payment detail page"); // This is another type of logging, with the help of TestNg Reporter //log // This has to be very carefully used, you should only print the very //important message in to this // This will populate the logs in the TestNG HTML reports // I have used this Reporter log just once in this whole module Reporter.log("Payment is successfully perfromed for the purchased //product."); }catch(Exception e){ throw(e); } } } |
Confirmation Page Action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package appModules;
import org.testng.Reporter;
import pageObjects.BaseClass;
import pageObjects.Confirmation_Page;
// This is called Modularization, when we club series of actions in to one Module
// For Modular Driven Framework, please see
//http://www.toolsqa.com/selenium-webdriver/modular-driven/ public class Confirmation_Action { // I could have created a Function for it but I keep calculations in //Functions and test steps in Module Actions // It could have been avoided and simply put these steps in Test Case, //it depends totally on you, everybody has their own choice public static void Execute() throws Exception{ // This is to get the Product name on the Confirmation page with //using getText() method // Confirmation_Page.sProductName is a static variable and can be //used anywhere with its class name // Once some text is stored in this variable can be used later in //any other class Confirmation_Page.sProductName=Confirmation_Page.txt_ProductName().getText(); // This is all about Verification checks, these does not stop your //execution but simply report fail at the end // This is to check that if the value in the variable sProductName //is not null, then do this if(!"".equals(Confirmation_Page.sProductName)){ // Here I have put a verification check on the Product Name, //if it is displayed my verification will pass Reporter.log("Verification Passed for Product Name on //Confirmation page"); }else{ // If it not displayed then the verification check is failed Reporter.log("Verification Failed for Product Name on //Confirmation page"); // If the above verification gets failed then I have to report //this to my test and fail the test accordingly // To achieve this, I have initialized this variable of //Base class at the start of my test with value true in it // At the end of my test, i will match the value, if it //will be false then I will fail the test, else the test will be pass BaseClass.bResult=false; } Confirmation_Page.sProductPrice= Confirmation_Page.txt_ProductPrice().getText(); if(!"".equals(Confirmation_Page.sProductPrice)){ Reporter.log("Verification Passed for Product Price on Confirmation page"); }else{ Reporter.log("Verification Failed for Product Price on Confirmation page"); BaseClass.bResult=false; } } } |
Verification Action
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package appModules;
import org.testng.Reporter;
import pageObjects.BaseClass;
import pageObjects.CheckOut_Page;
import pageObjects.Confirmation_Page;
// This is called Modularization, when we club series of actions in to one Module
// For Modular Driven Framework, please see
//http://www.toolsqa.com/selenium-webdriver/modular-driven/ public class Verification_Action { // I could have created a Function for it but I keep calculations in //Functions and test steps in Module Actions // It could have been avoided and simply put these steps in Test Case, //it depends totally on you, everybody has their own choice public static void Execute() throws Exception{ // This is to check that if the Product Name stored from Checkout & //Confirmation page is same // These are static variables, see how easy is to use them in your test if(CheckOut_Page.sProductName.equals(Confirmation_Page.sProductName)){ // Here I have put a verification check on the Product Name, //if it is matched, my verification will pass Reporter.log("Verification Passed for Product Name"); }else{ // If it not matched then the verification check is failed Reporter.log("Verification Failed for Product Name"); // If the above verification gets failed then I have to report //this to my test and fail the test accordingly // To achieve this, I have initialized this variable of Base class at //the start of my test with value true in it // At the end of my test, i will match the value, if it will be false //then I will fail the test, else the test will be pass BaseClass.bResult=false; } if(CheckOut_Page.sProductPrice.equals(Confirmation_Page.sProductPrice)){ Reporter.log("Verification Passed for Product Price"); }else{ Reporter.log("Verification Failed for Product Price"); BaseClass.bResult=false; } } } |
Utility Package
Constant Variable Class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package utility;
public class Constant {
public static final String URL = "http://www.store.demoqa.com";
public static final String Username = "testuser_1";
public static final String Password ="Test@123";
public static final String Path_TestData =
"D://ToolsQA//OnlineStore//src//testData//"; public static final String File_TestData = "TestData.xlsx"; //Test Data Sheet Columns public static final int Col_TestCaseName = 0; public static final int Col_UserName =1 ; public static final int Col_Password = 2; public static final int Col_Browser = 3; public static final int Col_ProductType = 4; public static final int Col_ProductNumber = 5; public static final int Col_FirstName = 6; public static final int Col_LastName = 7; public static final int Col_Address = 8; public static final int Col_City = 9; public static final int Col_Country = 10; public static final int Col_Phone = 11; public static final int Col_Email = 12; public static final int Col_Result = 13; public static final String Path_ScreenShot = "D://ToolsQA//OnlineStore//src//Screenshots//"; } |
No comments:
Post a Comment