Step1)Create maven project and then create all the package structures like below
Step2)Add required dependencies in po.xml
Maven Repository: org.seleniumhq.selenium » selenium-java (mvnrepository.com)
Maven Repository: org.testng » testng (mvnrepository.com)
Maven Repository: org.apache.commons » commons-lang3 (mvnrepository.com)
Maven Repository: commons-io » commons-io (mvnrepository.com)
Maven Repository: org.apache.poi » poi (mvnrepository.com)
Maven Repository: org.apache.poi » poi-ooxml (mvnrepository.com)
Maven Repository: org.apache.logging.log4j » log4j-core (mvnrepository.com)
Maven Repository: org.apache.logging.log4j » log4j-api (mvnrepository.com)
https://mvnrepository.com/artifact/com.aventstack/chaintest-testngMaven Repository: io.qameta.allure » allure-testng » 2.20.1 (mvnrepository.com)
Step 3)Create WebDriverFactory.java & TestBase.java classes under package com.qa.opencart.factory;
and Constants.java file under package com.qa.opencart.utils
WebDriverFactory class code:
-------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
TestBase class code:
-------------------------------------------------------------------------------------------------------------------------
============================================================================================================================================
Step 4) Adding logs under src/test/resource folder-->create file log4j2.xml file
log4j.xml ------------------------------------------------------------------------------------------------------------------------------------------------------------
Step5)Create config.properties file under src/test/resource/config package
"============================================================" Step6)Create chaintest.propertiesfiles under src/test/resource package
---------------------------------------------------------------------------------------------------------------------- allure.properties file code
--------------------------------------------------------------------------------------------------------------- Step3.1)Create a Constants.java class under com/qa/opencart/utils package
--------------------------------------------------------------------------------------------------------------- Step3.2)Create a JavaScriptUtils.java class under com/qa/opencart/utils package
--------------------------------------------------------------------------------------------------------------- Step3.3)Create a TimeUtils.java class under com/qa/opencart/utils package
--------------------------------------------------------------------------------------------------------------- Step3.4)Create a ExcelUtils.java class under com/qa/opencart/utils package
--------------------------------------------------------------------------------------------------------------- Step3.5)Create a WebDriverUtils.java class under com/qa/opencart/utils package
--------------------------------------------------------------------------------------------------------------- Step4.1)Create HomePage.java class under com/qa/opencart/pages package
--------------------------------------------------------------------------------------------------------------- Step4.2)Create RegistrationPage.java class under com/qa/opencart/pages package
--------------------------------------------------------------------------------------------------------------- Step4.3)Create LoginPage.java class under com/qa/opencart/pages package
--------------------------------------------------------------------------------------------------------------- Step5.1)Create HomePageTest.java class under com/qa/opencart/testcases package
--------------------------------------------------------------------------------------------------------------- LogoutPage.java code
package com.qa.opencart.pages;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.qa.opencart.utilities.Constants;
import com.qa.opencart.utilities.WebDriverUtils;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class LogoutPage extends WebDriverUtils{
public LogoutPage(WebDriver driver){
super(driver);
PageFactory.initElements(driver,this);
}
@FindBy(xpath="//h1[normalize-space()='Account Logout']")
private WebElement accountLogoutHeader;
@FindBy(xpath="//a[normalize-space()='Continue']")
private WebElement continueBtn;
@FindBy(css="#content p")
private WebElement accountLoggedOffMsg;
@FindBy(xpath="//*[@id='common-success']/ul/li[3]/a")
private WebElement logoutBreadCrumb;
public String getLogoutPageTitle(){
return getTitle();
}
public String getLogoutPageUrl(){
return waitForUrlContains(Constants.LOGOUT_PAGE_FRACTION_URL);
}
public void clickContinueBtn(){
try{
ChainTestListener.log("Click on continue button");
click(continueBtn);
}catch(NoSuchElementException|InterruptedException ex){
ChainTestListener.log("Unable to click on continue button");
ex.printStackTrace();
}
}
public boolean isLogoutBreadCrumbExists(){
return logoutBreadCrumb.isDisplayed();
}
public boolean isAccountLogoutHeaderExists(){
return accountLogoutHeader.isDisplayed();
}
public boolean isAccountLoggedOffMsgExists(){
return accountLoggedOffMsg.isDisplayed();
}
}
--------------------------------------------------------------------------------------------------------------- MyAccountPage.java code
package com.qa.opencart.pages;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.qa.opencart.utilities.Constants;
import com.qa.opencart.utilities.WebDriverUtils;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class MyAccountPage extends WebDriverUtils{
public MyAccountPage(WebDriver driver){
super(driver);
PageFactory.initElements(driver,this);
}
@FindBy(xpath="//a[@title='My Account']")
private WebElement myAccountMenu;
@FindBy(xpath="//input[@placeholder='Search']")
private WebElement searchEditbox;
@FindBy(xpath="//button[@class='btn btn-default btn-lg']")
private WebElement searchTorchIcon;
@FindBy(xpath="//ul[@class='dropdown-menu dropdown-menu-right']//a[normalize-space()='Logout']")
private WebElement logoutLink;
@FindBy(css="body div[id='account-account'] ul[class='breadcrumb'] li:nth-child(1) a:nth-child(1)")
private WebElement accountBreadCrumb;
@FindBy(css="#content h2")
private List MyAccountHeaderList;
@FindBy(xpath="//*[@id='top-links']/ul/li[2]/ul/li/a")
private List myAccountMenuOptionsList;
@FindBy(xpath="//i[@class='fa fa-home']")
private WebElement homeIcon;
@FindBy(xpath="//*[@id=\"account-account\"]/ul/li[2]/a[normalize-space()='Account']")
private WebElement myaccountBreadCrumb;
public String getMyAccountPageTitle(){
return getTitle();
}
public String getMyAccountPageUrl(){
return waitForUrlContains(Constants.MY_ACCOUNT_PAGE_FRACTION_URL);
}
public void clickMyAccountMenu(){
try{
ChainTestListener.log("Click on my account menu");
click(myAccountMenu);
}catch(NoSuchElementException|InterruptedException ex){
ChainTestListener.log("Unable to click on my account menu");
ex.printStackTrace();
}
}
public boolean isLogoutExists(){
clickMyAccountMenu();
return logoutLink.isDisplayed();
}
public boolean isMyAccountBreadCrumbExists(){
return myaccountBreadCrumb.isDisplayed();
}
public void clickLogoutLink() throws InterruptedException{
try{
if(isLogoutExists()){
ChainTestListener.log("Click on logout link under myaccount menu");
click(logoutLink);
}
}catch(NoSuchElementException ex){
ex.printStackTrace();
}
}
public void navigateToHomePage() throws InterruptedException{
try{
ChainTestListener.log("click on Home icon on breadcrumb");
click(homeIcon);
}catch(NoSuchElementException ex){
ChainTestListener.log("Unable to click home icon");
}
}
public List getMyAccountMenuOptionList(){
ListmyAccountMenuOptionsTextList = new ArrayList<>();
try{
clickMyAccountMenu();
for(WebElement option:myAccountMenuOptionsList){
String text = option.getText();
myAccountMenuOptionsTextList.add(text);
}
}catch(Exception ex){
ex.printStackTrace();
}
return myAccountMenuOptionsTextList;
}
public List getMyAccountHeaderOptionsList(){
ListmyAccountHeaderOptionsTextList = new ArrayList<>();
try{
clickMyAccountMenu();
for(WebElement option:MyAccountHeaderList){
String text = option.getText();
myAccountHeaderOptionsTextList.add(text);
}
}catch(Exception ex){
ex.printStackTrace();
}
return myAccountHeaderOptionsTextList;
}
public ResultsPage doProductSearch(String productName){
ChainTestListener.log("searching for the product:"+productName);
try{
ChainTestListener.log("type the product in the search field");
type(searchEditbox,productName);
ChainTestListener.log("click on search torch icon");
click(searchTorchIcon);
}catch(InterruptedException e){
throw new RuntimeException(e);
}
return new ResultsPage(driver);
}
public void pressEscapeKey(){
Actions act = new Actions(driver);
act.sendKeys(Keys.ESCAPE).perform();
}
}
--------------------------------------------------------------------------------------------------------------- PageFactoryManager.java code
package com.qa.opencart.pages;
import org.openqa.selenium.WebDriver;
public class PageFactoryManager{
private WebDriver driver;
public PageFactoryManager(WebDriver driver) {
this.driver = driver;
}
public HomePage getHomePage() { return new HomePage(driver); }
public LoginPage getLoginPage() { return new LoginPage(driver); }
public RegisterPage getRegisterPage() { return new RegisterPage(driver); }
public MyAccountPage getMyAccountPage() { return new MyAccountPage(driver); }
public ProductDetailsPage getProductDetailsPage(){
return new ProductDetailsPage(driver);
}
public ResultsPage getResultsPage(){
return new ResultsPage(driver);
}
public LogoutPage getLogoutPage(){
return new LogoutPage(driver);
}
}
--------------------------------------------------------------------------------------------------------------- ProductDetailsPage.java code
package com.qa.opencart.pages;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.qa.opencart.utilities.TimeUtils;
import com.qa.opencart.utilities.WebDriverUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Map;
public class ProductDetailsPage extends WebDriverUtils{
public ProductDetailsPage(WebDriver driver){
super(driver);
PageFactory.initElements(driver,this);
}
@FindBy(css="div[id='content'] h1")
private WebElement productNameHeader;
@FindBy(xpath="//ul[@class='thumbnails']//li")
private List ProductImageList;
@FindBy(xpath="(//div[@id='content']/div/div[2]/ul[@class='list-unstyled'])[position()=1]/li")
private List productMetadataList;
@FindBy(xpath="(//div[@id='content']/div/div[2]/ul[@class='list-unstyled'])[position()=2]/li")
private List productPriceList;
@FindBy(xpath="//i[@class='fa fa-home']")
private WebElement homeIcon;
@FindBy(xpath="//ul[@class='breadcrumb']//li[1]")
private WebElement productNameBreadCrumb;
@FindBy(id="input-quantity")
private WebElement quantityEditbox;
@FindBy(id="button-cart")
private WebElement addToCartBtn;
@FindBy(css=".alert.alert-success.alert-dismissible")
private WebElement productAddedToCartSuccessMessage;
@FindBy(xpath="//a[normalize-space()='shopping cart']")
private WebElement shoppingCartLink;
public String getProductDetailsPageTitle(){
return getTitle();
}
public String getProductName(){
return productNameHeader.getText();
}
public void navigateToShoppingCartPage(){
try{
ChainTestListener.log("Click on shoppingcart link");
click(shoppingCartLink);
}catch(NoSuchElementException|InterruptedException ex){
ChainTestListener.log("Unable to click on shoppingcart link");
ex.printStackTrace();
}
}
public String getAddToCartSuccessMessage(){
return productAddedToCartSuccessMessage.getText();
}
public int getProductImageCount(){
return ProductImageList.size();
}
public void clickAddToCartButton() throws InterruptedException{
try{
ChainTestListener.log("click add to cart button");
click(addToCartBtn);
}catch(NoSuchElementException ex){
ex.printStackTrace();
}
}
public void setQuantity(String quantity) throws InterruptedException{
ChainTestListener.log("Entering the product quantity in quantity editbox");
type(quantityEditbox,quantity);
}
public void navigateToHomePage() throws InterruptedException{
try{
ChainTestListener.log("click on Home icon on breadcrumb");
click(homeIcon);
}catch(NoSuchElementException ex){
ChainTestListener.log("Unable to click home icon");
}
}
private MapproductMap;
private void getProductMetadata(){
ChainTestListener.log("fetch the product metadata");
ChainTestListener.log("fproduct metadata count is:"+productMetadataList.size());
for(WebElement pmd:productMetadataList){
String metaText = pmd.getText();
ChainTestListener.log("split metatext based on :");
String[] metaDataArray = metaText.split(":");
ChainTestListener.log("fethc meta key and value");
String metaKey = metaDataArray[0].trim();
String metaValue = metaDataArray[1].trim();
//insert key and value into map
productMap.put(metaKey,metaValue);
}
}
private void getProductPriceData(){
ChainTestListener.log("product meta price count is:"+productPriceList.size());
String price = productPriceList.get(0).getText().trim();
String extraTaxPrice = productPriceList.get(1).getText().trim();
ChainTestListener.log("store the price value in the map");
productMap.put("actualPrice",price);
productMap.put("actualTaxPrice",extraTaxPrice);
}
public Map getProductInformation(){
productMap = new HashMap<>();
getProductMetadata();
getProductPriceData();
return productMap;
}
}
--------------------------------------------------------------------------------------------------------------- ResultsPage.java code
package com.qa.opencart.pages;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.qa.opencart.utilities.Constants;
import com.qa.opencart.utilities.TimeUtils;
import com.qa.opencart.utilities.WebDriverUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class ResultsPage extends WebDriverUtils{
public ResultsPage(WebDriver driver){
super(driver);
PageFactory.initElements(driver,this);
}
@FindBy(css="div[id='content'] h1")
private WebElement searchResultsHeader;
@FindBy(xpath="//*[@id='product-search']/ul/li[2]/a")
private WebElement searchBreadCrumb;
@FindBy(css="div[class*='product-layout product-grid']")
private List searchProductList;
@FindBy(xpath="//span[normalize-space()='My Account']")
private WebElement myAccountMenu;
@FindBy(xpath="//ul[@class='dropdown-menu dropdown-menu-right']//a[normalize-space()='My Account']")
private WebElement myAccountOption;
@FindBy(xpath="//i[@class='fa fa-home']")
private WebElement homeIcon;
public String getResultsPageTitle(){
return getTitle();
}
public void clickMyAccountMenu(){
try{
ChainTestListener.log("Click on my account menu");
click(myAccountMenu);
ChainTestListener.log("Click on my account option");
click(myAccountOption);
}catch(NoSuchElementException|InterruptedException ex){
ChainTestListener.log("Unable to click on my account menu");
ex.printStackTrace();
}
}
public boolean isSearchResultsHeaderExists(){
return searchResultsHeader.isDisplayed();
}
public boolean isSearchResultsBreadCrumbExists(){
return searchBreadCrumb.isDisplayed();
}
public void selectProduct(String productName) throws InterruptedException{
try{
ChainTestListener.log("selecting the desired product from results:"+productName);
click(getElement(By.linkText(productName)));
TimeUtils.smallWait();
}catch(NoSuchElementException ex){
ex.printStackTrace();
}
}
public void navigateToHomePage() throws InterruptedException{
try{
ChainTestListener.log("click on Home icon on breadcrumb");
click(homeIcon);
}catch(NoSuchElementException ex){
ChainTestListener.log("Unable to click home icon");
}
}
public int getProductListSize(){
ChainTestListener.log("fetch the total number of products count");
return searchProductList.size();
}
}
--------------------------------------------------------------------------------------------------------------- LoginPageTest.java code
package com.qa.opencart.testcases;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.qa.opencart.factory.TestBase;
import com.qa.opencart.factory.WebDriverFactory;
import com.qa.opencart.pages.*;
import com.qa.opencart.utilities.Constants;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.IOException;
public class LoginPageTest extends TestBase{
public HomePage homePage;
public RegisterPage registerPage;
public LoginPage loginPage;
public MyAccountPage myAccountPage;
public LogoutPage logoutPage;
@BeforeClass
public void pageClassesSetup() throws InterruptedException{
PageFactoryManager pageFactory = new PageFactoryManager(driver);
homePage= pageFactory.getHomePage();
registerPage = pageFactory.getRegisterPage();
loginPage = pageFactory.getLoginPage();
myAccountPage = pageFactory.getMyAccountPage();
logoutPage = pageFactory.getLogoutPage();
ChainTestListener.log("navigate to login page");
homePage.navigateToLoginrPage();
}
@Test(description ="TC01_Verify the login page title")
public void TC01_Verify_the_login_page_title_Test(){
ChainTestListener.log("TC01_Verify the login page title");
Assert.assertEquals(loginPage.getLoginPageTitle(),Constants.LOGIN_PAGE_TITLE);
}
@Test(description ="TC02_Verify the login breadcrumb test")
public void TC02_Verify_the_login_breadcrumb_Test(){
ChainTestListener.log("TC02_Verify_the_breadcrumb_Test");
Assert.assertTrue(loginPage.isloginBreadCrumbExists(),"login breadcrumb doesnot exists ");
}
@Test(description ="TC03_Verify the login page elemnts existance test")
public void TC03_Verify_the_login_page_elemnts_existance_Test(){
ChainTestListener.log("TC03_Verify_the_login_page_elemnts_existance_Test");
Assert.assertTrue(loginPage.isNewCustomerHeaderExists(),"New customer header doesnot exists ");
Assert.assertTrue(loginPage.isReturningCustomerHeaderExists(),"Returning customer header doesnot exists ");
}
@Test(description ="TC04_Verify navigate to register page from login page test")
public void TC04_Verify_navigate_to_register_page_from_login_page_Test() throws InterruptedException{
ChainTestListener.log("TC04_Verify_navigate_to_register_page_from_login_page_Test");
loginPage.clickNewCustomerContinueButton();
registerPage.waitForPageLoad(1000);
ChainTestListener.log("Verifyregister_page_title");
Assert.assertEquals(registerPage.getRegisterPageTitle(),Constants.REGISTRATION_PAGE_TITLE);
ChainTestListener.log("navigate back to login pge");
registerPage.navigateToLoginPage();
}
@Test(description ="TC05_Verify navigate to forgot password page from login page test",dependsOnMethods={"TC04_Verify_navigate_to_register_page_from_login_page_Test"})
public void TC05_Verify_navigate_to_forgot_password_page_from_login_page_Test() throws InterruptedException{
ChainTestListener.log("TC05_Verify_navigate_to_forgot_password_page_from_login_page_Test");
Assert.assertTrue(loginPage.isReturningCustomerHeaderExists(),"Returning customer header doesnot exists ");
Assert.assertTrue(loginPage.isloginBreadCrumbExists(),"login breadcrumb doesnot exists ");
loginPage.navigateToForgotPasswordPage();
loginPage.waitForPageLoad(1000);
ChainTestListener.log("navigate back to login pge");
driver.navigate().back();
}
@Test(description ="TC06_Verify empty credentials error message in login page test")
public void TC06_Verify_empty_credentials_login_page_Test() throws InterruptedException{
ChainTestListener.log("TC06_Verify_empty_credentials_login_page_Test");
loginPage.doLogin(" ", " ");
loginPage.waitForPageLoad(1000);
ChainTestListener.log("verify the empty credentials error message");
Assert.assertTrue(loginPage.getEmptyCredentialsErrorMsg().contains(Constants.EMPTY_CREDS_ERROR_MSG));
}
@Test(description ="TC07_Verify valid credentials test",dependsOnMethods={"TC06_Verify_empty_credentials_login_page_Test"})
public void TC07_Verify_valid_credentials_login_page_Test() throws InterruptedException, IOException{
ChainTestListener.log("TC07_Verify_valid_credentials_login_page_Test");
loginPage.doLogin(WebDriverFactory.readPropertyValue("username"),WebDriverFactory.readPropertyValue("pwd"));
myAccountPage.waitForPageLoad(1000);
ChainTestListener.log("verify the my account page title");
Assert.assertEquals(myAccountPage.getMyAccountPageTitle(),Constants.MYACCOUNT_PAGE_TITLE);
}
@Test(description="TC08_Verify_logout_from_My_Account_Page",dependsOnMethods={"TC07_Verify_valid_credentials_login_page_Test"})
public void TC08_Verify_logout_from_My_Account_Page_Test() throws InterruptedException{
ChainTestListener.log("TC08_Verify_logout_from_My_Account_Page_Test..has started");
myAccountPage.clickLogoutLink();
logoutPage.waitForPageLoad(2000);
ChainTestListener.log("Verify logout page title");
Assert.assertEquals(logoutPage.getLogoutPageTitle(),Constants.LOGOUT_PAGE_TITLE);
ChainTestListener.log("click continue button in logout page..");
logoutPage.clickContinueBtn();
homePage.waitForPageLoad(1000);
Assert.assertEquals(homePage.getHomePageTitle(),Constants.HOME_PAGE_TITLE);
}
}
--------------------------------------------------------------------------------------------------------------- RegistrationTest.java code
package com.qa.opencart.testcases;
import com.aventstack.chaintest.plugins.ChainTestListener;
import com.github.javafaker.Faker;
import com.qa.opencart.factory.TestBase;
import com.qa.opencart.factory.WebDriverFactory;
import com.qa.opencart.pages.*;
import com.qa.opencart.utilities.Constants;
import com.qa.opencart.utilities.ExcelUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.Assert;
import org.testng.annotations.*;
import java.io.IOException;
public class RgisterPageTest extends TestBase{
public HomePage homePage;
public RegisterPage registerPage;
public LoginPage loginPage;
public MyAccountPage myAccountPage;
public LogoutPage logoutPage;
String fname,lname,email,telephone;
@BeforeTest
public void testDataSetup(){
ChainTestListener.log("Generating the Fake test data using Faker class");
Faker fkObj = new Faker();
fname = fkObj.address().firstName();
lname = fkObj.address().lastName();
email = fkObj.internet().emailAddress();
telephone = fkObj.phoneNumber().phoneNumber();
}
@BeforeClass
public void pageClassesSetup(){
PageFactoryManager pageFactory = new PageFactoryManager(driver);
homePage= pageFactory.getHomePage();
registerPage = pageFactory.getRegisterPage();
loginPage = pageFactory.getLoginPage();
myAccountPage = pageFactory.getMyAccountPage();
logoutPage = pageFactory.getLogoutPage();
}
@BeforeMethod
public void navigate_to_register_page_from_home_page_Test() throws InterruptedException{
ChainTestListener.log("TC04_Verify_navigate_to_register_page_from_home_page_Test");
homePage.navigateToRegisterPage();
registerPage.waitForPageLoad(2000);
ChainTestListener.log("Verifyregister_page_title");
Assert.assertEquals(registerPage.getRegisterPageTitle(),Constants.REGISTRATION_PAGE_TITLE);
}
@Test(description ="TC01_Verify register an account using faker data")
public void TC01_Verify_register_an_account_using_faker_test_data_Test(){
ChainTestListener.log("TC01_Verify_register_an_account_using_faker_test_data_Test");
try{
ChainTestListener.log("Enter personal details");
registerPage.setpersonalDetails(fname,lname,email,telephone);
ChainTestListener.log("Generate the password");
String pwd =WebDriverFactory.randomAlphaNumeric();
registerPage.setPasswordEditbox(pwd);
registerPage.setConfirmPasswordEditbox(pwd);
ChainTestListener.log("Select the subscribe option yes or no");
registerPage.selectSubscribe("Yes");
ChainTestListener.log("ceck the agree checkbox");
registerPage.checkAgreeCheckbox();
ChainTestListener.log("click on continue button");
registerPage.clickOnContinueButton();
registerPage.waitForPageLoad(2000);
ChainTestListener.log("Verify account created success message and header text");
wait.until(ExpectedConditions.visibilityOf(registerPage.getAccountCreatedHeaderExists()));
wait.until(ExpectedConditions.visibilityOf(registerPage.getAccountCreatedBreadCrumbSuccessLinkExists()));
ChainTestListener.log("Click on Continue button in account created register page");
registerPage.clickOnAccountCreatedContinueButton();
myAccountPage.waitForPageLoad(2000);
ChainTestListener.log("verify the my account page title");
Assert.assertEquals(myAccountPage.getMyAccountPageTitle(),Constants.MYACCOUNT_PAGE_TITLE);
}catch(Exception e){
ChainTestListener.log("Account created failed:"+e.getMessage());
e.printStackTrace();
}
}
@AfterMethod
public void TC08_Verify_logout_from_My_Account_Page_Test() throws InterruptedException{
ChainTestListener.log("TC08_Verify_logout_from_My_Account_Page_Test..has started");
myAccountPage.clickLogoutLink();
logoutPage.waitForPageLoad(2000);
ChainTestListener.log("Verify logout page title");
Assert.assertEquals(logoutPage.getLogoutPageTitle(),Constants.LOGOUT_PAGE_TITLE);
ChainTestListener.log("click continue button in logout page..");
logoutPage.clickContinueBtn();
homePage.waitForPageLoad(1000);
Assert.assertEquals(homePage.getHomePageTitle(),Constants.HOME_PAGE_TITLE);
}
@Test(description ="TC02_Verify_registering_an_account_with_excel_sheet_data_Test",dataProvider="excelTestData")
public void TC02_Verify_registering_an_account_with_excel_sheet_data_Test(String fName,String lName,String tel,String pwd,String subscribe){
ChainTestListener.log("TC02_Verify_registering_an_account_with_excel_sheet_data_Test");
int iteration =1;
try{
ChainTestListener.log("Enter personal details");
String randomEmail = WebDriverFactory.randomeString()+"@gmail.com";
registerPage.setpersonalDetails(fname,lname,randomEmail,telephone);
ChainTestListener.log("Generate the password");
registerPage.setPasswordEditbox(pwd);
registerPage.setConfirmPasswordEditbox(pwd);
ChainTestListener.log("Select the subscribe option yes or no");
registerPage.selectSubscribe("Yes");
ChainTestListener.log("ceck the agree checkbox");
registerPage.checkAgreeCheckbox();
ChainTestListener.log("click on continue button");
registerPage.clickOnContinueButton();
registerPage.waitForPageLoad(2000);
ChainTestListener.log("Verify account created success message and header text");
wait.until(ExpectedConditions.visibilityOf(registerPage.getAccountCreatedHeaderExists()));
wait.until(ExpectedConditions.visibilityOf(registerPage.getAccountCreatedBreadCrumbSuccessLinkExists()));
ChainTestListener.log("Click on Continue button in account created register page");
registerPage.clickOnAccountCreatedContinueButton();
myAccountPage.waitForPageLoad(2000);
ChainTestListener.log("verify the my account page title");
Assert.assertEquals(myAccountPage.getMyAccountPageTitle(),Constants.MYACCOUNT_PAGE_TITLE);
ChainTestListener.log("Accout "+iteration+" has been created successfully");
iteration++;
}catch(Exception e){
ChainTestListener.log("Account created failed:"+e.getMessage());
e.printStackTrace();
}
}
@DataProvider
public Object[][] excelTestData() throws IOException, InvalidFormatException{
Object[][] data = new ExcelUtils().getTestData(Constants.TEST_DATA_FILE_PATH,Constants.REGISTER_SHEET_NAME);
return data;
}
}
--------------------------------------------------------------------------------------------------------------- pom.xml code
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.qa.packages</groupId>
<artifactId>HybridOpencartAutomation-Nov-30-2025</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.38.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.20.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.25.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.25.2</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>chaintest-testng</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
--------------------------------------------------------------------------------------------------------------- testng.xml code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
<test verbose="2" preserve-order="true" name="Opencart-HomePageTest">
<classes>
<class name="com.qa.opencart.testcases.HomePageTest">
</class>
</classes>
</test>
<test verbose="2" preserve-order="true" name="Opencart-LoginPageTest">
<classes>
<class name="com.qa.opencart.testcases.LoginPageTest">
</class>
</classes>
</test>
<test verbose="2" preserve-order="true" name="Opencart-MyAccountPageTest">
<classes>
<class name="com.qa.opencart.testcases.MyAccountPageTest">
</class>
</classes>
</test>
<test verbose="2" preserve-order="true" name="Opencart-ProductDetailsPageTest">
<classes>
<class name="com.qa.opencart.testcases.ProductDetailsPageTest">
</class>
</classes>
</test>
<test verbose="2" preserve-order="true" name="Opencart-RegisterPageTest">
<classes>
<class name="com.qa.opencart.testcases.RgisterPageTest">
</class>
</classes>
</test>
</suite>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.