Commit e8cf8e58 authored by mrahim's avatar mrahim

UI testing

parents
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ 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_1_8" default="true" project-jdk-name="azul-1.8" 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="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</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 version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="c3a7bc8b-2204-42f3-aa01-260d573e34da" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/Main.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/com/example/StepDefinations/AddToCartSteps.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/src/main/java/org/example/Main.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/test/java/com/example/PageObjects/AddToCartPage.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/test/java/com/example/StepDefinations/AddToCartSteps.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/test/java/com/example/TestRunner.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/test/resources/Feature/AddToCart.feature" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2AfH0CQp0h14adWjnKeNZyEHHvG" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "/Users/mrahim/Desktop/UI testing"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/main/resources" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.example" />
</key>
</component>
<component name="RunManager" selected="TestNG.TestRunner">
<configuration name="Feature: AddToCart" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java" temporary="true" nameIsGenerated="true">
<option name="CUCUMBER_CORE_VERSION" value="5" />
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/resources/Feature/AddToCart.feature" />
<option name="GLUE" value="com.example.StepDefinations" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="WebTest" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter" />
<option name="SUGGESTED_NAME" value="Feature: AddToCart" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.cucumber.core.cli.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Scenario: To verify 1000-Monthly donation for One-time added to the cart" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java" temporary="true" nameIsGenerated="true">
<option name="CUCUMBER_CORE_VERSION" value="5" />
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/resources/Feature/AddToCart.feature" />
<option name="GLUE" value="com.example.StepDefinations" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="WebTest" />
<option name="NAME_FILTER" value="^To verify 1000\-Monthly donation for One\-time added to the cart$" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter --name &quot;^To verify 1000\-Monthly donation for One\-time added to the cart$&quot;" />
<option name="SUGGESTED_NAME" value="Scenario: To verify 1000-Monthly donation for One-time added to the cart" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.cucumber.core.cli.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Scenario: User should not be able to remove all the donation of 1000-Monthly Recurring donation to cart when remove the first donation to cart list" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java" temporary="true" nameIsGenerated="true">
<option name="CUCUMBER_CORE_VERSION" value="5" />
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/resources/Feature/AddToCart.feature" />
<option name="GLUE" value="com.example.StepDefinations" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="WebTest" />
<option name="NAME_FILTER" value="^User should not be able to remove all the donation of 1000\-Monthly Recurring donation to cart when remove the first donation to cart list$" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter --name &quot;^User should not be able to remove all the donation of 1000\-Monthly Recurring donation to cart when remove the first donation to cart list$&quot;" />
<option name="SUGGESTED_NAME" value="Scenario: User should not be able to remove all the donation of 1000-Monthly Recurring donation to cart when remove the first donation to cart list" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.cucumber.core.cli.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TestRunner" type="TestNG" temporary="true" nameIsGenerated="true">
<module name="WebTest" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.example.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="com.example" />
<option name="MAIN_CLASS_NAME" value="com.example.TestRunner" />
<option name="TEST_OBJECT" value="CLASS" />
<properties />
<listeners />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="TestNG.TestRunner" />
<item itemvalue="Cucumber Java.Scenario: User should not be able to remove all the donation of 1000-Monthly Recurring donation to cart when remove the first donation to cart list" />
<item itemvalue="Cucumber Java.Feature: AddToCart" />
<item itemvalue="Cucumber Java.Scenario: To verify 1000-Monthly donation for One-time added to the cart" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="c3a7bc8b-2204-42f3-aa01-260d573e34da" name="Changes" comment="" />
<created>1655393496042</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1655393496042</updated>
</task>
<servers />
</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>WebTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.2.2</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.testng</groupId>-->
<!-- <artifactId>testng</artifactId>-->
<!-- <version>7.6.0</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.3.4</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>7.3.4</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>7.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>6.6.6</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
browser=Chrome
Url=https://www.daraz.pk/
\ No newline at end of file
package com.example;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
@CucumberOptions(
plugin = {"pretty",
"html:target/cucumber-reports/cucumber.html",
"json:target/cucumber-reports/cucumber.json"
},
features = {"@target/failed_scenario.txt"},
glue = {"com.example.StepDefinations"},
monochrome = true,
tags = "@web"
)
public class FailedTestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object [][] scenarios() {
return super.scenarios();
}
}
\ No newline at end of file
package com.example.PageObjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class AddToCartPage {
public WebDriver driver;
public AddToCartPage(WebDriver driver) {
this.driver=driver;
}
public void searchProductFunction(String SearchProduct) {
driver.findElement(By.cssSelector("#q")).sendKeys(SearchProduct);
driver.findElement(By.xpath("//button[normalize-space()='SEARCH']")).click();
}
public void selectProduct(String selectProduct ) {
driver.findElement(By.xpath(String.format("//a[contains(text(),'%s')]",selectProduct))).click();
}
public void Button(String button) {
driver.findElement(By.xpath(String.format("//span[contains(text(),'%s')]",button))).click();
}
public void emailAddress(String phone , String password) throws InterruptedException {
Thread.sleep(7000);
int size = driver.findElements(By.tagName("iframe")).size();
driver.switchTo().frame(3);
driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col1 > div.mod-input.mod-login-input-loginName.mod-input-loginName > input[type=text]")).sendKeys(phone);
driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col1 > div.mod-input.mod-input-password.mod-login-input-password.mod-input-password > input[type=password]")).sendKeys(password);
driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col2 > div.mod-login-btn > button")).click();
driver.switchTo().defaultContent();
}
public void proceedToPayButtonLocator() {
driver.findElement(By.cssSelector(".checkout-order-total-button.automation-checkout-order-total-button-button")).click();
}
public void paymentTypes(String payment) {
driver.findElement(By.xpath(String.format("//div[@class='title'][normalize-space()='%s']", payment))).click();
}
public void clickButton() {
driver.findElement(By.cssSelector(".next-btn-large.checkout-order-total-button.automation-checkout-order-total-button-checkout")).click();
}
public void accountNumber(String text) {
driver.findElement(By.cssSelector("input[type='text']")).sendKeys(text);
}
public String errorMessage() {
return driver.findElement(By.cssSelector("div.payment-input div.error")).getText();
}
// public void jsExecutor(String locator) {
// WebElement element = driver.findElement(By.xpath(String.format("//button[normalize-space()='%s']",locator)));
// Actions actions = new Actions(driver);
// actions.moveToElement(element).click().perform();
// }
}
package com.example.PageObjects;
import org.openqa.selenium.WebDriver;
public class PagesObject {
public AddToCartPage addToCartPage;
public WebDriver driver;
public PagesObject(WebDriver driver)
{
this.driver=driver;
}
public AddToCartPage getAddToCartPage(){
addToCartPage=new AddToCartPage(driver);
return addToCartPage;
}
}
package com.example.StepDefinations;
import com.example.PageObjects.AddToCartPage;
import com.example.Utils.TextContextSetup;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;
import io.cucumber.java.en.When;
import org.testng.Assert;
public class AddToCartSteps {
TextContextSetup textContextSetup;
public AddToCartSteps(TextContextSetup textContextSetup){
this.textContextSetup=textContextSetup;
}
AddToCartPage addToCartPage;
@And("I search {string} product in search bar")
public void searchProduct(String product) {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
addToCartPage.searchProductFunction(product);
}
@When("I select product {string}")
public void iSelectProduct(String selectProduct) {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
addToCartPage.selectProduct(selectProduct);
}
@When("I press {string} Button")
public void iClickOnXxxxButton(String button) {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
addToCartPage.Button(button);
}
@When("I enter phone number {string} & password {string}")
public void iAddItemToCart(String phone,String Password) throws InterruptedException {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
addToCartPage.emailAddress(phone,Password);
}
@When("^I press 'Proceed to pay' button On checkout page$")
public void ProceedToPayButton() throws InterruptedException {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
Thread.sleep(4000);
addToCartPage.proceedToPayButtonLocator();
Thread.sleep(4000);
}
@When("I Select payment {string} method")
public void iSelectPayment(String paymentType) throws InterruptedException {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
Thread.sleep(2000);
addToCartPage.paymentTypes(paymentType);
}
@When("I press Check Out")
public void iPressButton() throws InterruptedException {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
Thread.sleep(4000);
addToCartPage.clickButton();
}
@When("I Enter account number {string}")
public void iShouldSeeDonationAddedToCart(String amount) throws InterruptedException {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
Thread.sleep(1000);
addToCartPage.accountNumber(amount);
}
@When("I should see {string} error message on payment page")
public void iShouldSeeFollowingDonationAddedToCart(DataTable error) throws Throwable {
AddToCartPage addToCartPage=textContextSetup.pagesObject.getAddToCartPage();
Thread.sleep(4000);
String actual=addToCartPage.errorMessage();
System.out.println("Error message on Web"+actual);
Assert.assertEquals(error,actual);
}
}
package com.example.StepDefinations;
import com.example.Utils.TextContextSetup;
import io.cucumber.java.After;
import io.cucumber.java.AfterStep;
import io.cucumber.java.Scenario;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
public class Hooks {
TextContextSetup textContextSetup;
public Hooks(TextContextSetup textContextSetup){
this.textContextSetup=textContextSetup;
}
@After
public void closingDriver() throws IOException {
textContextSetup.baseClass.WebDriverManager().quit();
}
@AfterStep
public void addScreenShot(Scenario scenario) throws IOException {
WebDriver driver= textContextSetup.baseClass.WebDriverManager();
if(scenario.isFailed())
{
File sourcePath=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
byte[] fileContent= FileUtils.readFileToByteArray(sourcePath);
scenario.attach(fileContent,"image/png","Error image");
}
}
}
package com.example;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
@CucumberOptions(
plugin = {"pretty",
"html:target/cucumber-reports/cucumber.html",
"json:target/cucumber-reports/cucumber.json",
"rerun:target/failed_scenario.txt"
},
features = {"src/test/resources/Feature/AddToCart.feature"},
glue = {"com.example.StepDefinations"},
monochrome = true,
tags = "@web"
)
public class TestRunner extends AbstractTestNGCucumberTests {
//
// @Override
// @DataProvider(parallel = true)
// public Object [][] scenarios() {
// return super.scenarios();
// }
}
\ No newline at end of file
package com.example.Utils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class BaseClass {
public WebDriver driver;
public WebDriver WebDriverManager() throws IOException {
FileInputStream fis=new FileInputStream(System.getProperty("user.dir")+"//src//main//resources//global.properties");
Properties prop=new Properties();
prop.load(fis);
String url=prop.getProperty("Url");
String browser_properties=prop.getProperty("browser");
String browser_maven=System.getProperty("browser");
String browser=browser_maven!=null ?browser_maven:browser_properties;
if(driver==null) {
if(browser.equalsIgnoreCase("chrome"))
{ //For chrome browser any other browser can add their
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
// if(prop.getProperty("browser").equalsIgnoreCase("firefox"))
// {
// //fire fox browser driver
//
// }
driver.get(url);
}
return driver;
}
}
package com.example.Utils;
import com.example.PageObjects.PagesObject;
import org.openqa.selenium.WebDriver;
import java.io.IOException;
public class TextContextSetup {
public WebDriver driver;
public PagesObject pagesObject;
public BaseClass baseClass;
public TextContextSetup() throws IOException {
baseClass=new BaseClass();
pagesObject=new PagesObject(baseClass.WebDriverManager());
}
}
Feature: Add_To_Cart
@web
Scenario: User should be add product to the cart in daraz App
When I search "Mobile" product in search bar
And I select product "Nokia 5.4 smartphone with a 6.39\" HD+ screen, 4GB"
And I press "Add to Cart" Button
And I enter phone number "03200477525" & password "qwerty123"
And I press Check Out
And I press 'Proceed to pay' button On checkout page
And I Select payment "Easypaisa" method
And I Enter account number "123"
Then I should see "Not a valid Easypaisa Account" error message on payment page
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Test Suite" verbose="1">
<test name="Regression Tests">
<classes>
<class name="com.example.TestRunner">
</class>
</classes>
</test>
</suite>
\ No newline at end of file
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