Automation QA Testing Course Content

HybridFramework - base Package classes


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)

Maven Repository: com.aventstack » extentreports (mvnrepository.com)

Maven 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 ExtentManager.java, TestAllureListener.java and ExtentReportListener.java classes under com/qa/opencart/listeners package

ExtentManager.java class code


----------------------------------------------------------------------------------------------------------------------
ExtentReportListener.java class code


------------------------------------------------------------------------------------------------------------
TestAllureListener.java class 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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.qa.opencart.utils.JavaScriptUtils;
import com.qa.opencart.utils.WebDriverUtils;

public class LogoutPage extends WebDriverUtils{

	private Logger log=LogManager.getLogger(LogoutPage.class.getName());
	JavaScriptUtils jsUtils;
	public LogoutPage(WebDriver driver) {
		super(driver);
		jsUtils=new JavaScriptUtils(driver) ;
	}

	@FindBy(css="div#content>h1")
	private WebElement accountLogoutHeader;
	@FindBy(css="div#content>p")
	private WebElement accountLoggedOffMsg;
	@FindBy(css="a.btn.btn-primary")
	private WebElement continueBtn;
	
}






---------------------------------------------------------------------------------------------------------------
MyAccountPage.java code

package com.qa.opencart.pages;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.qa.opencart.utils.JavaScriptUtils;
import com.qa.opencart.utils.WebDriverUtils;

public class MyAccountPage extends WebDriverUtils{

	private Logger log=LogManager.getLogger(MyAccountPage.class.getName());
	JavaScriptUtils jsUtils;
	public MyAccountPage(WebDriver driver) {
		super(driver);
		jsUtils=new JavaScriptUtils(driver) ;
	}
	//ul[@class='breadcrumb']/li[2]/a[text()='Account']
	//ul.breadcrumb>li:nth-child(2)>a
	@FindBy(css="ul.breadcrumb>li:nth-child(2)>a")
	private WebElement myaccountBreadcrumb;
	@FindBy(css="div#content>p")
	private WebElement accountLoggedOffMsg;
	@FindBy(css="a.btn.btn-primary")
	private WebElement continueBtn;

}






---------------------------------------------------------------------------------------------------------------
RegistrationTest.java code

package com.qa.opencart.testcase;

import org.testng.annotations.Test;

import com.qa.opencart.factory.TestBase;
import com.qa.opencart.factory.WebDriverFactory;
import com.qa.opencart.pages.HomePage;
import com.qa.opencart.pages.LoginPage;
import com.qa.opencart.pages.MyAccountPage;
import com.qa.opencart.pages.RegistrationPage;
import com.qa.opencart.utils.Constants;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;

public class RegistrationTest extends TestBase{
	private Logger log=LogManager.getLogger(RegistrationTest.class.getName());
  @BeforeClass
  public void beforeClass() throws InterruptedException {
	  log.info("initialising the page class objects");
	  homePg=new HomePage(driver);
	  regPg=new RegistrationPage(driver);
	 homePg.navigateToRegisterPage(); 
	   myaccountPg=new MyAccountPage(driver); 
  }

  @Test
  public void registrationTest() throws InterruptedException {
	 try {
		log.info("Verify the Registration page title");
		 regPg.waitForPageLoad(2000);
		 Assert.assertEquals(regPg.getTitle(), Constants.REGISTRATION_PAGE_TITLE);
		 String fname=WebDriverFactory.randomeString();
		 log.info("setting the first name:"+fname);
		 regPg.setFirstName(fname);
		 String lname=WebDriverFactory.randomeString();
		 log.info("setting the last name:"+lname);
		 regPg.setLastName(lname);
		 String email=WebDriverFactory.randomeString()+"@gmail.com";
		 log.info("setting the email:"+email);
		 regPg.setEmail(email);
		 String telephone=WebDriverFactory.randomeNumber();
		 log.info("setting the telephone:"+telephone);
		 regPg.setTelePhone(telephone);
		 String pwd=WebDriverFactory.randomAlphaNumeric();
		 log.info("setting the password value is:"+pwd);
		 regPg.setPassword(pwd);
		 regPg.setConfirmPassword(pwd);
		 log.info("select the subscribe option yes");
		 regPg.selectSubScribe("Yes");
		 log.info("check the Privacy policy checkbox");
		 regPg.checkAgreeCheckbox();
		 log.info("Click on Continue button");
		 regPg.clickContinueBtn();
		 regPg.waitForPageLoad(2000);
		 log.info("verify the Account Creation success message and  header ");
		 Assert.assertEquals(regPg.getAccountCreatedHeader(), Constants.YOUR_ACCNT_CREATED_HEADER);
		 Assert.assertEquals(regPg.getAccountCreatedSuccMsg(), Constants.YOUR_ACCNT_CREATED_SUCC_MSG);
		 log.info("click on Account Created Continue button");
		 regPg.clickAccountCreatedContinueBtn();
		 log.info("validate the my Account Page title");
		Assert.assertEquals(myaccountPg.getTitle(), Constants.MY_ACCOUNT_PAGE_TITLE);
	} catch (InterruptedException e) {
		log.info("Account creation failed");
		e.printStackTrace();
	}
  
  }
  
  
}





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.