Skip to content

Sakif1997/Automation_testing_WebSite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Daraz-Web-Site (Automation testing with Allure Report)

Goals

Setting up a browser that will contain the testing process

Our primary goal is to validate the login/signup option on the Daraz home page, as well as test the login page with invalid input to see if it returns a proper response.

Because the Customer Care option on the homepage takes some time (delay) to show the Help Center option, the next goal is to access the route to get to the Help Center page

Maven file Setup

Create maven project and setup pomfile

pom.xml

Change or add dependencies

  <dependencies>     <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
   <groupId>org.testng</groupId>
   <artifactId>testng</artifactId>
   <version>7.6.1</version>
   <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
   <version>5.3.0</version>
</dependency>
<dependency>
   		<groupId>io.qameta.allure</groupId>
   		<artifactId>allure-testng</artifactId>
   		<version>2.19.0</version>
   	</dependency>
   </dependencies>

add plugins

<build>
   	<plugins>
   		<plugin>
   			<groupId>org.apache.maven.plugins</groupId>
   			<artifactId>maven-surefire-plugin</artifactId>
   			<version>3.0.0-M7</version>
   				<configuration>
   					<includes>
   						<include>${testfile}</include><!--Cmd te file name dibo Terminal a likhbo[mvn test -Dtestfile="logInTest.java"]-->
   					</includes>
   				</configuration>
   			<!-- <configuration>
   				<suiteXmlFiles>
   					<suiteXmlFile>${testXmlfile}</suiteXmlFile>
   				</suiteXmlFiles>
   			</configuration>-->
   		</plugin>

   	</plugins>
   </build>

Overall pom.xml file

<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>com.bd</groupId>
 <artifactId>Daraz23jan</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>Daraz23jan</name>
 <url>http://maven.apache.org</url>

 <properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
 </properties>

 <dependencies>     <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
   <groupId>org.testng</groupId>
   <artifactId>testng</artifactId>
   <version>7.6.1</version>
   <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
   <version>5.3.0</version>
</dependency>
<dependency>
   		<groupId>io.qameta.allure</groupId>
   		<artifactId>allure-testng</artifactId>
   		<version>2.19.0</version>
   	</dependency>
   </dependencies>
   <build>
   	<plugins>
   		<plugin>
   			<groupId>org.apache.maven.plugins</groupId>
   			<artifactId>maven-surefire-plugin</artifactId>
   			<version>3.0.0-M7</version>
   				<configuration>
   					<includes>
   						<include>${testfile}</include><!--Cmd te file name dibo Terminal a likhbo[mvn test -Dtestfile="logInTest.java"]-->
   					</includes>
   				</configuration>
   			<!-- <configuration>
   				<suiteXmlFiles>
   					<suiteXmlFile>${testXmlfile}</suiteXmlFile>
   				</suiteXmlFiles>
   			</configuration>-->
   		</plugin>

   	</plugins>
   </build>
</project>

Dynamicly design for test cases

Browser Setup

create a package under src/test/java and under the package(Utilites) create a class(BrowserSetup) folders

This code contain to setup browser and manage window for generate testing in automated way

package Utilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

import io.github.bonigarcia.wdm.WebDriverManager;


public class BrowserSetup {
   private static String browserName = System.getProperty("browser","chrome");
   private static final ThreadLocal<WebDriver> Driverlocal = new ThreadLocal<>();//to focus individual 
   public static WebDriver getDriver() {
   	return Driverlocal.get();
   }
   public static void setDriver(WebDriver driver) { 
   	//filename.threadlocalname.set()
   	BrowserSetup.Driverlocal.set(driver);
   }
   public static WebDriver getBrowser(String browserName) {
   	switch(browserName.toLowerCase()){
   	case "chrome":
   			WebDriverManager.chromedriver().setup();
   			return new ChromeDriver();
   	case "Edge":
   			WebDriverManager.edgedriver().setup();
   			return new EdgeDriver();
   	case "firefox":
   			WebDriverManager.firefoxdriver().setup();
   			return new FirefoxDriver();
   	default:
   		throw new RuntimeException("Browser not found");
   	}	
   }
   @BeforeSuite
   public static synchronized void setBrowser() {
   	WebDriver webdriver = getBrowser(browserName);
   	webdriver.manage().window().maximize();
   	setDriver(webdriver);
   }
   @AfterSuite
   public static synchronized void quitBrowser() {
   	getDriver().quit();
   }
   
}

BrowserSetup

Pages and testcases

Pages

create a package under src/test/java and under the package(Pages) create some classes which will contain page related objects and methods to generate testcases dynamicly foldersPages

It will be easier to understand if we named the class as page name or feature we will be testing for

BasePage : contain methods(findElement,click,wait, write , allureScreenshot)

package pages;

import static Utilities.BrowserSetup.getDriver;

import java.io.ByteArrayInputStream;
import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.qameta.allure.Allure;
public class BasePage{
   public WebElement getElement(By locator) {
   	return getDriver().findElement(locator);
   }
   public void clickOnElement(By locator) {
   	getElement(locator).click();
   }
   public String getElementText(By locator) {
   	return getElement(locator).getText();
   }
   public void clickonWaitelement(By locator) {
   	WebDriverWait waitElement = new WebDriverWait(getDriver(),Duration.ofSeconds(20));
   	WebElement  element= waitElement.until(ExpectedConditions.elementToBeClickable(locator));
   	element.click();	
   }
   public void write(By locator, String text) {
   	getElement(locator).sendKeys(text);
   }
   public void TakeScreenShot(String name) {
   	Allure.addAttachment(name, new ByteArrayInputStream(((TakesScreenshot)getDriver()).getScreenshotAs(OutputType.BYTES)));
   }

}

BasePage

Extends BasePage classes

LogInPage

login page location, login form fillup with valid or invalid credentials loginPage

package pages;

import org.openqa.selenium.By;

public class LogInPage extends BasePage{
	public String LOGINPAGETITLE ="Daraz.com.bd: Online Shopping Bangladesh - Mobiles, Tablets, Home Appliances, TV, Audio &amp; More";
	public By emailfield = By.xpath("//input[@type='text']");
	public By passField =By.xpath("//input[@type='password']");
	public By loginButton =By.xpath("//button[contains(text(),'LOGIN')]");
	public void loginFormFillup(String email, String pass) {
		write(emailfield, email);
		write(passField,pass);
		TakeScreenShot("Invalid Inputs");

		clickOnElement(loginButton);
		TakeScreenShot("Invalid input outcome");
	}

}

pic

DarazHomePage

loginbutton location HomePage

package pages;

import org.openqa.selenium.By;

public class DarazHomePage extends BasePage{
	public By LOGINSIGNUPBUTTON = By.xpath("//a[contains(text(),'Signup / Login')]");

	
	public void clickLogin(){
		clickOnElement(LOGINSIGNUPBUTTON);
		TakeScreenShot("login");
	}

}

HelpCenterPage

CustomerCare to HelpCenter page Helpcenter

package pages;

import org.openqa.selenium.By;


public class HelpCenter extends BasePage{
	public By CustomerCareOption = By.xpath("//span[contains(text(),'CUSTOMER CARE')]");
	public By HelpCenterPage = By.xpath("//a[contains(text(),'Help Center')]");
	public String helpCenterPageTitle ="Daraz.com.bd: Online Shopping Bangladesh - Mobiles, Tablets, Home Appliances, TV, Audio &amp; More";
	public void helpCenter() {
		clickOnElement(CustomerCareOption);
		TakeScreenShot("Homepage Customer Care Option");
		clickonWaitelement(HelpCenterPage);
		TakeScreenShot("HelpcenterPage");

		
	}
	
}



## TestCases

This code manage window for generate testing in automated way and Also seperate form of testing pages which make easier to Understand the process 




### HelpCenterOption 
```ruby
package testCases;

import org.testng.annotations.Test;

import Utilities.BrowserSetup;
import io.qameta.allure.Description;
import pages.HelpCenter;


public class HelpCenterOption extends BrowserSetup{
	
	HelpCenter helpcenter = new HelpCenter();
	@Test (description = "Customer Care Route" )
	@Description("HopePage to Cutomer Care Option")
	public void DarazCustomerCare() throws InterruptedException{
		getDriver().get("https://www.daraz.com.bd/");
		helpcenter.helpCenter();
	
		Thread.sleep(4000);
		
	}
	

}

HelpCenterToPage

loginPage

package testCases;

import static org.testng.Assert.assertEquals;

import org.testng.annotations.Test;

import Utilities.BrowserSetup;
import io.qameta.allure.Description;
import pages.DarazHomePage;
import pages.LogInPage;

public class logInTest extends BrowserSetup {
	DarazHomePage darazHomePage = new DarazHomePage();
	LogInPage logInPage =new LogInPage();
	@Test(description = "Login Page Route")
	@Description ("Invalid entities Response in Login page")
	public void logInPageTitle() throws InterruptedException {
		getDriver().get("https://www.daraz.com.bd/");
		darazHomePage.clickLogin();
		Thread.sleep(2000);
		assertEquals(getDriver().getTitle(),logInPage.LOGINPAGETITLE);
		System.out.println(getDriver().getTitle());
		Thread.sleep(2000);
		logInPage.loginFormFillup("[email protected]", "1235");
		Thread.sleep(5000);
	}
	

}

login

Releases

No releases published

Packages

No packages published