Commit 3a85402b authored by Muhammad Hasan Khan's avatar Muhammad Hasan Khan

MY Project

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Selenium_Daraz" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="wsgc-snapshot-repo" />
<option name="name" value="WSGC Snapshot Repository" />
<option name="url" value="http://snapshotrepo.wsgc.com/snapshotrepo" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="wsgc-dev-repo" />
<option name="name" value="WSGC Artifactory Dev Repository" />
<option name="url" value="http://artifactory.wsgc.com/artifactory/dev" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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.example</groupId>
<artifactId>Selenium_Daraz</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Selenium_Daraz</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<!-- <configuration>-->
<!-- <suiteXmlFiles>-->
<!-- <suiteXmlFile>testng.xml</suiteXmlFile>-->
<!-- </suiteXmlFiles>-->
<!-- </configuration>-->
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
baseurl = https://www.daraz.pk
email = hasanbunny99@gmail.com
password = hasankhan03122148866
searchproduct = iphone
invalidCNIC = 123456789
\ No newline at end of file
package org.example;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Feature: Daraz App test flow
Scenario: Add to cart
Given user is navigated to daraz page
And user searches a product and clicks on it, Add to cart button appears
When user clicks on Add to cart, user navigated to login window
And user sign in with valid credentials
Then user is navigated to added cart window and clicks on checkout
And user should see Order summary
When user enters invalid credential
Then user should see error message
\ No newline at end of file
package PageFactory;
import common.Common;
import config.Config;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.io.IOException;
public class Add_to_cart {
WebDriver driver;
Config config = new Config();
@FindBy(xpath = Common.SEARCH_BAR_ID)
WebElement search_bar;
@FindBy(xpath = Common.BTN_SEARCH)
WebElement btn_search;
@FindBy(xpath = Common.PRODUCT)
WebElement btn_product;
@FindBy(xpath = Common.BTN_ADD_TO_CART)
WebElement btn_addToCart;
@FindBy(xpath = Common.EMAIL_ID)
WebElement email_id;
@FindBy(xpath = Common.PASSWORD)
WebElement password;
@FindBy(className = Common.BTN_LOGIN)
WebElement btn_login;
@FindBy(xpath = Common.BTN_CHECKOUT)
WebElement btn_checkout;
@FindBy(xpath = Common.I_FRAME)
WebElement iframe;
@FindBy(xpath = Common.BTN_EDIT)
WebElement btn_edit;
@FindBy(xpath = Common.ENTER_CNIC)
WebElement enter_cnic;
@FindBy(xpath = Common.BTN_SAVE)
WebElement btn_save;
@FindBy(xpath = Common.ERROR_MESSAGE)
WebElement error_message;
public Add_to_cart(WebDriver driver) throws IOException {
this.driver = driver;
PageFactory.initElements(driver, this);
}
public void searchProduct() {
search_bar.sendKeys(config.getSearchProduct());
}
public void searchButton() {
btn_search.click();
}
public void product() {
btn_product.click();
}
public void addToCart() {
btn_addToCart.click();
}
public void email_id() {
driver.switchTo().frame(iframe);
email_id.sendKeys(config.getEmail());
}
public void password() {
password.sendKeys(config.getPassword());
}
public void login() {
btn_login.click();
}
public void checkout() {
btn_checkout.click();
}
public void editButton() {
btn_edit.click();
enter_cnic.sendKeys(config.getInvalidCNIC());
btn_save.click();
}
public void errorMessage(){
error_message.getText();
}
}
package Runner;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/java/Feature"},
glue = {"StepDefinitions"},
monochrome = true,
plugin = {"pretty", "html:target/HTMLReport.html",
"json:target/JsonReport.json",
"junit:target/JunitReport.xml"}
)
public class TestRunner {
}
package StepDefinitions;
import PageFactory.Add_to_cart;
import common.Common;
import config.Config;
import driver.Driver;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import java.io.IOException;
public class Steps_AddToCart {
WebDriver driver;
Config config = new Config();
Add_to_cart cart;
public Steps_AddToCart() throws IOException {
}
@Given("user is navigated to daraz page")
public void userIsNavigatedToDarazPage() throws IOException {
this.driver = Driver.chrome();
driver.navigate().to(config.getBaseUrl());
cart = new Add_to_cart(driver);
}
@And("user searches a product and clicks on it, Add to cart button appears")
public void userSearchesAProductAndClicksOnItAddToCartButtonAppears() throws InterruptedException {
cart.searchProduct();
Thread.sleep(Common.TIME_IN_SECONDS);
cart.searchButton();
Thread.sleep(Common.TIME_IN_SECONDS);
cart.product();
Assert.assertTrue(driver.getPageSource().contains(Common.TITLE));
}
@When("user clicks on Add to cart, user navigated to login window")
public void userClicksOnAddToCartUserNavigatedToLoginWindow() throws InterruptedException {
cart.addToCart();
Thread.sleep(Common.TIME_IN_SECONDS);
Assert.assertTrue(driver.getPageSource().contains(Common.TITLE2));
}
@And("user sign in with valid credentials")
public void userSignInWithValidCredentials() throws InterruptedException {
cart.email_id();
cart.password();
Thread.sleep(Common.TIME_IN_SECONDS);
cart.login();
Thread.sleep(Common.TIME_IN_SECONDS);
}
@Then("user is navigated to added cart window and clicks on checkout")
public void userIsNavigatedToAddedCartWindow() throws InterruptedException {
Thread.sleep(Common.TIME_IN_SECONDS);
cart.checkout();
Thread.sleep(Common.TIME_IN_SECONDS);
}
@And("user should see Order summary")
public void userShouldSeeProceedToPayButton() {
Assert.assertTrue(driver.getPageSource().contains(Common.TITLE4));
}
@When("user enters invalid credential")
public void userEntersInvalidCredential() {
cart.editButton();
}
@Then("user should see error message")
public void userShouldSeeErrorMessage() {
cart.errorMessage();
driver.close();
}
}
package common;
public class Common {
//----Timer----//
public static final int TIME_IN_SECONDS = 10;
public static final int TIME_IN_SECONDS2 = 50;
//----Page_Title----//
public static final String TITLE = "Add to Cart";
public static final String TITLE2 = "Welcome! Please Login to continue.";
public static final String TITLE3 = "1 new item(s) have been added to your cart";
public static final String TITLE4 = "Order Summary";
//----Common_Id----//
//----Common_ClassName----//
public static final String BTN_LOGIN = "mod-login-btn";
//----Common_XPath----//
public static final String SEARCH_BAR_ID = "//input[contains(@id,'q')]";
public static final String BTN_SEARCH = "//*[@id=\"topActionHeader\"]/div/div[2]/div/div[2]/form/div/div[2]/button";
public static final String PRODUCT = "//*[@id=\"root\"]/div/div[2]/div/div/div[1]/div[2]/div[1]/div/div/div[2]/div[2]/a";
public static final String PASSWORD = "/html/body/div[2]/div/div[2]/div/div/div/div[2]/form/div/div[1]/div[2]/input";
public static final String BTN_ADD_TO_CART = "//*[@id=\"module_add_to_cart\"]/div/button[2]";
public static final String EMAIL_ID = "/html/body/div[2]/div/div[2]/div/div/div/div[2]/form/div/div[1]/div[1]/input";
public static final String BTN_CHECKOUT = "//button[contains(@type,'button')and normalize-space(text())='CHECK OUT']";
public static final String I_FRAME = "//*[@id=\"dialog-body-1\"]/iframe";
public static final String BTN_EDIT = "//*[@id=\"textEdit_11010\"]/div/a";
public static final String ENTER_CNIC = "//*[@id=\"textEdit_11010-form\"]/div[1]/div/input";
public static final String BTN_SAVE = "//*[@id=\"textEdit_11010-form\"]/div[2]/button";
public static final String ERROR_MESSAGE = "//*[@id=\"textEdit_11010-form\"]/div[1]/div/span";
}
package config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class Config {
String BaseUrl;
String Email;
String Password;
String SearchProduct;
String InvalidCNIC;
public String getBaseUrl() {
return BaseUrl;
}
public String getEmail() {
return Email;
}
public String getPassword() {
return Password;
}
public String getSearchProduct() {
return SearchProduct;
}
public String getInvalidCNIC() {
return InvalidCNIC;
}
public static Properties fileUtil() throws IOException {
File src = new File("src/Input.properties");
FileInputStream file = new FileInputStream(src);
Properties prop = new Properties();
prop.load(file);
return prop;
}
public Config() throws IOException {
this.BaseUrl = fileUtil().getProperty("baseurl");
this.Email = fileUtil().getProperty("email");
this.Password = fileUtil().getProperty("password");
this.SearchProduct = fileUtil().getProperty("searchproduct");
this.InvalidCNIC = fileUtil().getProperty("invalidCNIC");
}
}
package driver;
import common.Common;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class Driver {
public static WebDriver chrome(){
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(Common.TIME_IN_SECONDS2, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(Common.TIME_IN_SECONDS2, TimeUnit.SECONDS);
driver.manage().window().maximize();
return driver;
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2022-08-11T08:51:35.531Z",
"line": 3,
"name": "Add to cart",
"description": "",
"id": "daraz-app-test-flow;add-to-cart",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 41214904000,
"status": "passed"
},
"line": 4,
"name": "user is navigated to daraz page",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userIsNavigatedToDarazPage()"
},
"keyword": "Given "
},
{
"result": {
"duration": 39979991000,
"status": "passed"
},
"line": 5,
"name": "user searches a product and clicks on it, Add to cart button appears",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userSearchesAProductAndClicksOnItAddToCartButtonAppears()"
},
"keyword": "And "
},
{
"result": {
"duration": 274942000,
"status": "passed"
},
"line": 6,
"name": "user clicks on Add to cart, user navigated to login window",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userClicksOnAddToCartUserNavigatedToLoginWindow()"
},
"keyword": "When "
},
{
"result": {
"duration": 4693382000,
"status": "passed"
},
"line": 7,
"name": "user sign in with valid credentials",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userSignInWithValidCredentials()"
},
"keyword": "And "
},
{
"result": {
"duration": 5542552000,
"status": "passed"
},
"line": 8,
"name": "user is navigated to added cart window and clicks on checkout",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userIsNavigatedToAddedCartWindow()"
},
"keyword": "Then "
},
{
"result": {
"duration": 201358000,
"status": "passed"
},
"line": 9,
"name": "user should see Order summary",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userShouldSeeProceedToPayButton()"
},
"keyword": "And "
},
{
"result": {
"duration": 550157000,
"status": "passed"
},
"line": 10,
"name": "user enters invalid credential",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userEntersInvalidCredential()"
},
"keyword": "When "
},
{
"result": {
"duration": 209631000,
"status": "passed"
},
"line": 11,
"name": "user should see error message",
"match": {
"location": "StepDefinitions.Steps_AddToCart.userShouldSeeErrorMessage()"
},
"keyword": "Then "
}
]
}
],
"name": "Daraz App test flow",
"description": "",
"id": "daraz-app-test-flow",
"keyword": "Feature",
"uri": "file:src/test/java/Feature/Daraz.feature",
"tags": []
}
]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="1" time="92.99">
<testcase classname="Daraz App test flow" name="Add to cart" time="92.772">
<system-out>
<![CDATA[Given user is navigated to daraz page.......................................passed
And user searches a product and clicks on it, Add to cart button appears....passed
When user clicks on Add to cart, user navigated to login window.............passed
And user sign in with valid credentials.....................................passed
Then user is navigated to added cart window and clicks on checkout..........passed
And user should see Order summary...........................................passed
When user enters invalid credential.........................................passed
Then user should see error message..........................................passed
]]>
</system-out>
</testcase>
</testsuite>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment