From cbdfd42bce4d882fe0f3fe24f0f7015116b1b8a9 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Fri, 8 Nov 2024 22:24:07 +0100 Subject: [PATCH 01/35] JUnit Test Framework Design --- .gitignore | 3 ++ pom.xml | 27 ++++++++++- .../junittestingframework/JunitTestDemo.java | 47 +++++++++++++++++++ .../junittestingframework/JunitTestDemo1.java | 47 +++++++++++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 src/test/java/junittestingframework/JunitTestDemo.java create mode 100644 src/test/java/junittestingframework/JunitTestDemo1.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e96e85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +.idea/ +SeleniumJavaTests.iml/ diff --git a/pom.xml b/pom.xml index 2bfacaf..4da6da8 100644 --- a/pom.xml +++ b/pom.xml @@ -57,9 +57,34 @@ 4.3.1 - + + org.junit.platform + junit-platform-launcher + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine + test + + + + + org.junit + junit-bom + 5.11.3 + pom + import + + + diff --git a/src/test/java/junittestingframework/JunitTestDemo.java b/src/test/java/junittestingframework/JunitTestDemo.java new file mode 100644 index 0000000..11868d6 --- /dev/null +++ b/src/test/java/junittestingframework/JunitTestDemo.java @@ -0,0 +1,47 @@ +package junittestingframework; + +import org.junit.jupiter.api.*; + +/** + * @author : ismetsasaq + * @created : 08/11/2024,21:26 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class JunitTestDemo { + @BeforeAll + public static void beforeAllMethod(){ + System.out.println("Before all runs once"); + } + @BeforeEach + public void beforeEachMethod(){ + System.out.println("Before each method.."); + } + + @Test + + public void addCustomerTest(){ + System.out.println("Add customer test.."); + Assertions.assertTrue(10>9); + + } + @Test + + public void editCustomer(){ + System.out.println("Edit customer test"); + Assertions.assertEquals(10,10); + } + +@Test + + public void deleteCustomer(){ + System.out.println("Delete customer test"); +} +@AfterEach + public void afterEachMethod(){ + System.out.println("After each method"); +} +@AfterAll + public static void afterAllMethod(){ + System.out.println("After all runs once"); +} +} diff --git a/src/test/java/junittestingframework/JunitTestDemo1.java b/src/test/java/junittestingframework/JunitTestDemo1.java new file mode 100644 index 0000000..1e4413d --- /dev/null +++ b/src/test/java/junittestingframework/JunitTestDemo1.java @@ -0,0 +1,47 @@ +package junittestingframework; + +import org.junit.jupiter.api.*; + +/** + * @author : ismetsasaq + * @created : 08/11/2024,21:26 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class JunitTestDemo1 { + @BeforeAll + public static void beforeAllMethod(){ + System.out.println("Before all runs once"); + } + @BeforeEach + public void beforeEachMethod(){ + System.out.println("Before each method.."); + } + + @Test + @Order(1) + public void addCustomerTest(){ + System.out.println("Add customer test.."); + Assertions.assertTrue(10>9); + + } + @Test + @Order(2) + public void editCustomer(){ + System.out.println("Edit customer test"); + Assertions.assertEquals(10,10); + } + +@Test +@Order(3) + public void deleteCustomer(){ + System.out.println("Delete customer test"); +} +@AfterEach + public void afterEachMethod(){ + System.out.println("After each method"); +} +@AfterAll + public static void afterAllMethod(){ + System.out.println("After all runs once"); +} +} From e4473dd08c82c9180954ac419d52b22ca6979a72 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Sun, 10 Nov 2024 16:00:07 +0100 Subject: [PATCH 02/35] JUnit Test Framework Design --- pom.xml | 6 ++- .../pageobjectdesignpattern/BaseClass.java | 21 ++++++++ .../CustomerListPage.java | 54 +++++++++++++++++++ .../DashboardPage.java | 34 ++++++++++++ .../FunctionsLibrary.java | 30 +++++++++++ .../pageobjectdesignpattern/LoginPage.java | 41 ++++++++++++++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/test/java/pageobjectdesignpattern/BaseClass.java create mode 100644 src/test/java/pageobjectdesignpattern/CustomerListPage.java create mode 100644 src/test/java/pageobjectdesignpattern/DashboardPage.java create mode 100644 src/test/java/pageobjectdesignpattern/FunctionsLibrary.java create mode 100644 src/test/java/pageobjectdesignpattern/LoginPage.java diff --git a/pom.xml b/pom.xml index 4da6da8..f9a903c 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,11 @@ junit-vintage-engine test - + + net.datafaker + datafaker + 2.4.1 + diff --git a/src/test/java/pageobjectdesignpattern/BaseClass.java b/src/test/java/pageobjectdesignpattern/BaseClass.java new file mode 100644 index 0000000..f29b8eb --- /dev/null +++ b/src/test/java/pageobjectdesignpattern/BaseClass.java @@ -0,0 +1,21 @@ +package pageobjectdesignpattern; + +import org.openqa.selenium.chrome.ChromeDriver; + +/** + * @author : ismetsasaq + * @created : 10/11/2024,11:09 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class BaseClass { + ChromeDriver driver; + public void openBrowser(){ + driver =new ChromeDriver(); + driver.manage().window().maximize(); + driver.get("https://mahara.org/?login"); + } + public void closeBrowser(){ + driver.close(); + driver.quit(); + } +} diff --git a/src/test/java/pageobjectdesignpattern/CustomerListPage.java b/src/test/java/pageobjectdesignpattern/CustomerListPage.java new file mode 100644 index 0000000..6eb27c5 --- /dev/null +++ b/src/test/java/pageobjectdesignpattern/CustomerListPage.java @@ -0,0 +1,54 @@ +package pageobjectdesignpattern; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +/** + * @author : ismetsasaq + * @created : 09/11/2024,23:01 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class CustomerListPage { + ChromeDriver driver; + FunctionsLibrary functionsLibrary; + @FindBy(linkText ="Add Customer") + WebElement addCustomerLink; + @FindBy(id = "cust-title") + WebElement titleField; + @FindBy(id = "cust-firstname") + WebElement firstNameField; + @FindBy(id = "cust-lastname") + WebElement lastNameField; + @FindBy(id = "cust-email") + WebElement emailField; + @FindBy(name = "save") + WebElement saveButton; + @FindBy(id = "ddd") + WebElement customerAddEddSuccessMessage; + + + public CustomerListPage(ChromeDriver driver){ + this.driver=driver; + PageFactory.initElements(driver,this); + functionsLibrary=new FunctionsLibrary(); + + } + public void addCustomer(String title, String firstName,String lastName,String email){ + functionsLibrary.waitForElementPresent(addCustomerLink); + addCustomerLink.click(); + functionsLibrary.waitForElementPresent(titleField); + titleField.sendKeys(title); + functionsLibrary.waitForElementPresent(firstNameField); + firstNameField.sendKeys(firstName); + functionsLibrary.waitForElementPresent(lastNameField); + lastNameField.sendKeys(lastName); + functionsLibrary.waitForElementPresent(emailField); + emailField.sendKeys(email); + functionsLibrary.waitForElementPresent(saveButton); + saveButton.click(); + } + + +} diff --git a/src/test/java/pageobjectdesignpattern/DashboardPage.java b/src/test/java/pageobjectdesignpattern/DashboardPage.java new file mode 100644 index 0000000..43006d9 --- /dev/null +++ b/src/test/java/pageobjectdesignpattern/DashboardPage.java @@ -0,0 +1,34 @@ +package pageobjectdesignpattern; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +/** + * @author : ismetsasaq + * @created : 09/11/2024,22:44 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class DashboardPage { + ChromeDriver driver; + FunctionsLibrary functionsLibrary; + @FindBy(linkText = "Customer List") + WebElement customerListLink; + @FindBy(css = "i.fa.fa-sign-out") + WebElement loginLink; + public DashboardPage(ChromeDriver driver){ + this.driver=driver; + PageFactory.initElements(driver,this); + functionsLibrary=new FunctionsLibrary(); + } + public void clickCustomerListLink(){ + functionsLibrary.waitForElementPresent(customerListLink); + customerListLink.click(); + + } + public void logout(){ + functionsLibrary.waitForElementPresent(loginLink); + loginLink.click(); + } +} diff --git a/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java b/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java new file mode 100644 index 0000000..da1e833 --- /dev/null +++ b/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java @@ -0,0 +1,30 @@ +package pageobjectdesignpattern; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; + +/** + * @author : ismetsasaq + * @created : 09/11/2024,22:31 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class FunctionsLibrary { + ChromeDriver driver; + public void sleep(int seconds){ + try { + Thread.sleep(seconds*1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + public void waitForElementPresent(WebElement element){ + WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds((6)).getSeconds()); + wait.until(ExpectedConditions.visibilityOf(element)); + + } +} diff --git a/src/test/java/pageobjectdesignpattern/LoginPage.java b/src/test/java/pageobjectdesignpattern/LoginPage.java new file mode 100644 index 0000000..2faa8e8 --- /dev/null +++ b/src/test/java/pageobjectdesignpattern/LoginPage.java @@ -0,0 +1,41 @@ +package pageobjectdesignpattern; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +/** + * @author : ismetsasaq + * @created : 09/11/2024,22:12 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class LoginPage { + ChromeDriver driver; + FunctionsLibrary functionsLibrary; + @FindBy(id ="username") + WebElement userNameField; + @FindBy(id ="password") + WebElement passwordField; + @FindBy(id ="login") + WebElement loginButton; + + + public LoginPage(ChromeDriver driver) { + this.driver = driver; + PageFactory.initElements(driver,this); + functionsLibrary=new FunctionsLibrary(); + + } + +public void login(String userName,String password){ + functionsLibrary.waitForElementPresent(userNameField); + userNameField.sendKeys(userName); + functionsLibrary.waitForElementPresent(passwordField); + passwordField.sendKeys(password); + functionsLibrary.waitForElementPresent(loginButton); + loginButton.click(); + } + +} From f89423ad91f8de17869d2737c8d6398f5ca60dce Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Sun, 10 Nov 2024 21:59:42 +0100 Subject: [PATCH 03/35] TestNG Annotation and attributes. --- pom.xml | 8 +++ .../java/testngframework/TestNGDemo1.java | 52 +++++++++++++++++++ .../java/testngframework/TestNGDemo2.java | 51 ++++++++++++++++++ .../java/testngframework/TestNGDemo3.java | 19 +++++++ 4 files changed, 130 insertions(+) create mode 100644 src/test/java/testngframework/TestNGDemo1.java create mode 100644 src/test/java/testngframework/TestNGDemo2.java create mode 100644 src/test/java/testngframework/TestNGDemo3.java diff --git a/pom.xml b/pom.xml index f9a903c..b32177f 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,14 @@ datafaker 2.4.1 + + + org.testng + testng + 7.10.2 + test + + diff --git a/src/test/java/testngframework/TestNGDemo1.java b/src/test/java/testngframework/TestNGDemo1.java new file mode 100644 index 0000000..8896cfb --- /dev/null +++ b/src/test/java/testngframework/TestNGDemo1.java @@ -0,0 +1,52 @@ +package testngframework; + +import com.beust.ah.A; +import org.testng.Assert; +import org.testng.annotations.*; + +/** + * @author : ismetsasaq + * @created : 10/11/2024,19:26 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class TestNGDemo1 { + @BeforeClass + public void beforeClass(){ + System.out.println("Before class runs once before all"); + + } + @BeforeMethod + public void beforeMethod(){ + System.out.println("Before method runs once before each test method"); + } + @AfterMethod + public void afterMethod(){ + System.out.println("after method runs once after each test method"); + } + @Test + public void addCustomerTest(){ + System.out.println("Add customer test"); + Assert.assertEquals("Add Customer","Add Customer"); + } + @Test + public void editCustomerTest(){ + System.out.println("Edit Customer Test"); + Assert.assertTrue("Customer Name".contains("Name")); + } + @Test + public void deleteCustomer(){ + System.out.println("Delete customer test.."); + Assert.assertTrue(19>9); + + } + @Test + public void addProduct(){ + System.out.println("Add Product test"); + Assert.assertTrue(11>10); + } + @AfterClass + public void afterClass(){ + System.out.println("After class runs once after all tests"); + + } +} diff --git a/src/test/java/testngframework/TestNGDemo2.java b/src/test/java/testngframework/TestNGDemo2.java new file mode 100644 index 0000000..12432e1 --- /dev/null +++ b/src/test/java/testngframework/TestNGDemo2.java @@ -0,0 +1,51 @@ +package testngframework; + +import org.testng.Assert; +import org.testng.annotations.*; + +/** + * @author : ismetsasaq + * @created : 10/11/2024,19:26 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class TestNGDemo2 { + @BeforeClass + public void beforeClass(){ + System.out.println("Before class runs once before all"); + + } + @BeforeMethod + public void beforeMethod(){ + System.out.println("Before method runs once before each test method"); + } + @AfterMethod + public void afterMethod(){ + System.out.println("after method runs once after each test method"); + } + @Test + public void addCustomerTest(){ + System.out.println("Add customer test"); + Assert.assertEquals("Add Customer","Add Customer"); + } + @Test + public void editCustomerTest(){ + System.out.println("Edit Customer Test"); + Assert.assertTrue("Customer Name".contains("Name")); + } + @Test(dependsOnMethods = "addCustomerTest") + public void deleteCustomer(){ + System.out.println("Delete customer test.."); + Assert.assertTrue(19>9); + + } + @Test + public void addProduct(){ + System.out.println("Add Product test"); + Assert.assertTrue(11>10); + } + @AfterClass + public void afterClass(){ + System.out.println("After class runs once after all tests"); + + } +} diff --git a/src/test/java/testngframework/TestNGDemo3.java b/src/test/java/testngframework/TestNGDemo3.java new file mode 100644 index 0000000..7fb26d6 --- /dev/null +++ b/src/test/java/testngframework/TestNGDemo3.java @@ -0,0 +1,19 @@ +package testngframework; + +import org.testng.annotations.Test; + +/** + * @author : ismetsasaq + * @created : 10/11/2024,21:52 + * @Email : noah.yisimaiti@Gmail.com + **/ +public class TestNGDemo3 { + @Test(invocationCount = 3,invocationTimeOut = 100) + public void myTest(){ + System.out.println("Test Pass!!"); + } + @Test(timeOut = 10) + public void test2(){ + System.out.println("Test 2..."); + } +} From 4d4f8c9c34f558c177ff5a090ca57b75ed0878c9 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Wed, 13 Nov 2024 07:02:38 +0100 Subject: [PATCH 04/35] TestNG Annotation and attributes. --- .idea/misc.xml | 2 +- .idea/workspace.xml | 271 ++++++++---------- SeleniumJavaTests.iml | 2 - .../unitedcoder/streamapi/FilterDemo1.java | 1 - .../uiautomation/AmazonSearch.java | 2 +- .../AddCustomerTest.java | 35 +++ .../pageobjectdesignpattern/BaseClass.java | 3 +- .../CustomerListPage.java | 30 +- .../DashboardPage.java | 19 +- .../FunctionsLibrary.java | 7 +- .../pageobjectdesignpattern/LoginPage.java | 17 +- .../testngframework/DataProviderDemo1.java | 22 ++ 12 files changed, 219 insertions(+), 192 deletions(-) delete mode 100644 SeleniumJavaTests.iml create mode 100644 src/test/java/pageobjectdesignpattern/AddCustomerTest.java create mode 100644 src/test/java/testngframework/DataProviderDemo1.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b661a5..9902dc5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6ce5d25..a42629f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,22 @@ + + - + + + + + + + + + + + + + - - + + @@ -35,43 +50,43 @@ - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.0", + "settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui" } -}]]> +} @@ -94,12 +171,12 @@ @@ -182,13 +259,6 @@ diff --git a/pom.xml b/pom.xml index b32177f..ba27aa8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,57 +5,54 @@ 4.0.0 org.example - SeleniumJavaTests + CubeCart202311 1.0-SNAPSHOT - - - - org.apache.commons - commons-lang3 - 3.9 - - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - - - joda-time - joda-time - 2.10.6 - - - - commons-io - commons-io - 2.6 - - - - org.apache.commons - commons-csv - 1.8 - - - - org.apache.poi - poi-ooxml - 4.1.2 - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - 2.11.3 - - - - io.rest-assured - json-path - 4.3.1 - + + + 17 + 17 + UTF-8 + + + + org.apache.commons + commons-lang3 + 3.13.0 + + + org.seleniumhq.selenium + selenium-java + 4.14.1 + + + io.github.bonigarcia + webdrivermanager + 5.3.0 + + + + commons-io + commons-io + 2.16.1 + + + + org.apache.poi + poi-ooxml + 5.2.3 + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.16.1 + + + + io.rest-assured + json-path + 5.3.1 + org.junit.platform @@ -84,8 +81,13 @@ 7.10.2 test + + joda-time + joda-time + 2.10.6 + - + diff --git a/src/main/java/com/unitedcoder/classconcepts/BankAccountStatic.java b/src/main/java/com/unitedcoder/classconcepts/BankAccountStatic.java deleted file mode 100644 index 2236e20..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/BankAccountStatic.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.unitedcoder.classconcepts; - -public class BankAccountStatic { - private static double accountBalance; - private static String accountName; - private static int accountNumber; - - public BankAccountStatic() { - } - - public static double getAccountBalance() { - return accountBalance; - } - - public static void setAccountBalance(double accountBalance) { - BankAccountStatic.accountBalance = accountBalance; - } - - public static String getAccountName() { - return accountName; - } - - public static void setAccountName(String accountName) { - BankAccountStatic.accountName = accountName; - } - - public static int getAccountNumber() { - return accountNumber; - } - - public static void setAccountNumber(int accountNumber) { - BankAccountStatic.accountNumber = accountNumber; - } - - //get account information - public static void getAccountInformation(){ - System.out.println(accountNumber); - System.out.println(accountName); - System.out.println(accountBalance); - } - //withdraw money - public static void withdrowMoney(double withdrawAmonut){ - if(withdrawAmonuti2){ - int result=Math.abs(i1-i2); - return result; -// } -// else { -// int result1=i2-i1; -// return result1; -// } - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/CalculatorTest.java b/src/main/java/com/unitedcoder/classconcepts/CalculatorTest.java deleted file mode 100644 index 9377dac..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/CalculatorTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.unitedcoder.classconcepts; - - -public class CalculatorTest { - public static void main(String[] args) { - Calculator c=new Calculator(); - c.calculatorInfo(); - System.out.println(c.addTwoNumbers(100,300)); - System.out.println(c.addTwoNumbers(200,500)); - System.out.println(c.addTwoNumbers("12","89")); - System.out.println(c.addTwoNumbers("12a","89")); - System.out.println(c.addMultipleNumbers(100,900,789,650,453,976)); - System.out.println(c.subtarctTwoNumbers(200,250)); - System.out.println("********Array Max Number*******"); - JavaMethods methods=new JavaMethods(); - System.out.println(methods.findMaxNumer(new int[]{10,5,90,2,89})); - System.out.println(methods.findMaxNumer(new int[]{10,5,90,2,200,89,20,500})); - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/Car.java b/src/main/java/com/unitedcoder/classconcepts/Car.java deleted file mode 100644 index c645fc4..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/Car.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.unitedcoder.classconcepts; - -public class Car implements Comparable { - //class level variables encapsulation - private String brand; - private String made; - private String color; - private String mileAge; - private long price; - private int year; - //default constructor - public Car() { - } - //constructor with arguments - public Car(String brand, String made, String color, String mileAge, long price, int year) { - this.brand = brand; - this.made = made; - this.color = color; - this.mileAge = mileAge; - this.price = price; - this.year = year; - } - //special method - public Car(String brand, String made, String color, String mileAge){ - this.brand = brand; - this.made = made; - this.color = color; - this.mileAge = mileAge; - } - - public Car(String brand, String color) { - this.brand = brand; - this.color = color; - } - - public Car(String brand, String color, long price) { - this.brand = brand; - this.color = color; - this.price = price; - } - - //define getter and setter method - public String getBrand() { - return brand; - } - - public void setBrand(String brand) {//local variable - this.brand = brand; - } - - public String getMade() { - return made; - } - - public void setMade(String made) { - this.made = made; - } - - public String getColor() { - return color; - } - - public void setColor(String color) { - this.color = color; - } - - public String getMileAge() { - return mileAge; - } - - public void setMileAge(String mileAge) { - this.mileAge = mileAge; - } - - public long getPrice() { - return price; - } - - public void setPrice(long price) { - this.price = price; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - - - public String toString() { -// return "Car{" + -// "brand='" + brand + '\'' + -// ", made='" + made + '\'' + -// ", color='" + color + '\'' + -// ", mileAge='" + mileAge + '\'' + -// ", price=" + price + -// ", year=" + year + -// '}'; - return brand+", "+made+", "+color+", "+mileAge+", "+price+", "+year; - } - - public String carInfo(){ - return brand+", "+made+", "+color+", "+mileAge+", "+price+", "+year; - } - - - @Override - public int compareTo(Car car) { - if(price==car.price){ - return 0; - }else if(price>car.price){ - return 1; - }else - return -1; - } -} - diff --git a/src/main/java/com/unitedcoder/classconcepts/ComparableDemo.java b/src/main/java/com/unitedcoder/classconcepts/ComparableDemo.java deleted file mode 100644 index a9a0a5c..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/ComparableDemo.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.unitedcoder.classconcepts; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; - -public class ComparableDemo { - public static void main(String[] args) { - ArrayList carList=new ArrayList<>(); - carList.add(new Car("Toyota","White",1000)); - carList.add(new Car("Honda","Black",10000)); - carList.add(new Car("BMW","Black",50000)); - carList.add(new Car("Benz","Green",100)); - System.out.println(carList.toString()); - - //comparable interface comparator method -// carList.sort(Comparator.comparing(Car::getPrice)); -// System.out.println(carList.toString()); -// carList.sort(Comparator.comparing(Car::getPrice).reversed()); -// System.out.println(carList.toString()); - Collections.sort(carList); - System.out.println(carList.toString()); - - - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/CubeCartAddProduct.java b/src/main/java/com/unitedcoder/classconcepts/CubeCartAddProduct.java deleted file mode 100644 index fca000a..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/CubeCartAddProduct.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.unitedcoder.classconcepts; - -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; -import org.openqa.selenium.support.ui.Select; - -public class CubeCartAddProduct { - public static void main(String[] args) { - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - ChromeOptions options = new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver = new ChromeDriver(options); - driver.manage().window().maximize(); - driver.get(""); - LoginUser user=new LoginUser("",""); - WebElement userNameField=driver.findElement(By.id("username")); - userNameField.sendKeys(user.getUserName()); - WebElement passwordField=driver.findElement(By.id("password")); - passwordField.sendKeys(user.getPassWord()); - WebElement loginButton=driver.findElement(By.id("login")); - loginButton.click(); - WebElement dashboard=driver.findElement(By.xpath("//div[@id=\"dashboard\"]/h3")); - String word=dashboard.getText(); - if(driver.getPageSource().contains(word)) - System.out.println("Login successfully"); - else - System.out.println("Login failed"); - WebElement productsLink=driver.findElement(By.id("nav_products")); - productsLink.click(); - WebElement addProductLink=driver.findElement(By.xpath("//*[text()='Add Product']")); - addProductLink.click(); - //aynigar10 20 30 - ProductContent content=new ProductContent("Aynigar"+System.currentTimeMillis(), - "pz7865"); - driver.findElement(By.id("name")).sendKeys(content.getProductName()); - driver.findElement(By.id("product_code")).sendKeys(content.getProductCode()); - WebElement dropDown=driver.findElement(By.id("condition")); - Select selectDropDown=new Select(dropDown); - selectDropDown.selectByValue("used"); - selectDropDown.selectByVisibleText(DropDownContent.Refurbished.name()); - driver.findElement(By.xpath("//input[@value='Save']")).click(); - String successfulMessage=driver.findElement(By.xpath("//div[@id=\"gui_message\"]/div[2]")).getText(); - if(driver.getPageSource().contains(successfulMessage)) - System.out.println("Product added successfully , test pass"); - else - System.out.println("Product not added , test failed"); - driver.close(); - driver.quit(); - - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/DropDownContent.java b/src/main/java/com/unitedcoder/classconcepts/DropDownContent.java deleted file mode 100644 index 478c1c5..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/DropDownContent.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.unitedcoder.classconcepts; - -public enum DropDownContent { - New,Used,Refurbished -} diff --git a/src/main/java/com/unitedcoder/classconcepts/EnumType.java b/src/main/java/com/unitedcoder/classconcepts/EnumType.java deleted file mode 100644 index 059d800..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/EnumType.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.unitedcoder.classconcepts; -enum level{ - LOW,MEDIUM,HIGH -} -public class EnumType { - public static void main(String[] args) { - // System.out.println(level.HIGH); - level l=level.HIGH; - switch (l){ - case HIGH: - System.out.println("High level"); - break; - case LOW: - System.out.println("Low level"); - break; - case MEDIUM: - System.out.println("Medium Level"); - break; - } - - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/FunctionLibrary.java b/src/main/java/com/unitedcoder/classconcepts/FunctionLibrary.java deleted file mode 100644 index 72f6994..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/FunctionLibrary.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.unitedcoder.classconcepts; - -import com.unitedcoder.excel.ExcelUtility; -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -import java.util.ArrayList; -import java.util.List; - -public class FunctionLibrary { - WebDriver driver;//class level gloable - - //define open browser method - public void openBrowser(String siteURL) { - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - ChromeOptions options = new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - driver = new ChromeDriver(options); - driver.manage().window().maximize(); - driver.get(siteURL); - } - - public void logIn(LoginUser user) { - WebElement userNameField = driver.findElement(By.id("username")); - userNameField.sendKeys(user.getUserName()); - WebElement passwordField = driver.findElement(By.id("password")); - passwordField.sendKeys(user.getPassWord()); - WebElement loginButton = driver.findElement(By.id("login")); - loginButton.click(); - } - - public void logIn(String username, String password) { - WebElement userNameField = driver.findElement(By.id("username")); - userNameField.sendKeys(username); - WebElement passwordField = driver.findElement(By.id("password")); - passwordField.sendKeys(password); - WebElement loginButton = driver.findElement(By.id("login")); - loginButton.click(); - } - - public boolean verifyLogin() { - WebElement logOutLink = driver.findElement(By.xpath("//div[@id=\"header\"]/span/a[2]")); - if (logOutLink.isDisplayed()) { - System.out.println("Login successfully"); - return true; - } else { - System.out.println("Login failed"); - return false; - } - } - - public void addProduct(String productName, String weight) { - WebElement addProductLink = driver.findElement(By.xpath("//*[text()='Add Product']")); - addProductLink.click(); - driver.findElement(By.id("name")).sendKeys(productName); - driver.findElement(By.name("product_weight")).sendKeys(weight); - driver.findElement(By.xpath("//input[@value='Save']")).click(); - } - - public void closeBrowser() { - driver.close(); - driver.quit(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/unitedcoder/classconcepts/GreetingPrinting.java b/src/main/java/com/unitedcoder/classconcepts/GreetingPrinting.java deleted file mode 100644 index 30902d5..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/GreetingPrinting.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.unitedcoder.classconcepts; - -import java.util.Date; - -public class GreetingPrinting implements Runnable{ - private String message; - - public GreetingPrinting(String message){ - this.message=message; - } - - @Override - public void run() { - for (int i = 0; i < 2; i++) { - Date date = new Date(); - System.out.println(date + " " + message); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/JavaMethods.java b/src/main/java/com/unitedcoder/classconcepts/JavaMethods.java deleted file mode 100644 index 371c095..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/JavaMethods.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.unitedcoder.classconcepts; - -public class JavaMethods { - /* int[] a=new int[]{9,10,3,20,5]; - int maxNumber=0; - for(int i=0;i carList=new ArrayList<>(); - carList.add(toyota);//add("A") - carList.add(honda); - carList.add(benz); - - for(Car cars:carList) { - // if(cars.getBrand().equalsIgnoreCase("toyota")){ - System.out.print(String.format("%s %s %s %s %d %d", - cars.getBrand(), - cars.getColor(), - cars.getMade(), - cars.getMileAge(), - cars.getPrice(), - cars.getYear() - )); - // } - System.out.println(); - } - - } - -} diff --git a/src/main/java/com/unitedcoder/classconcepts/VariableScope.java b/src/main/java/com/unitedcoder/classconcepts/VariableScope.java deleted file mode 100644 index 407f3d3..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/VariableScope.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.unitedcoder.classconcepts; - -public class VariableScope { - //Global variable---class level variable - static String name="Tom"; - int age=20; - - public static void main(String[] args) { - int i=10;//local variable - System.out.println(i+6); - System.out.println(i); - System.out.println(name); - VariableScope variableScope=new VariableScope(); - System.out.println(variableScope.age); - variableScope.sum(3); - add(10); - } - - public void sum(int a){ - //local variable only accessable within the method - int i=10; - int j=20; - int age=20; - } - public static void add(int a){ - - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/package1/Alpha.java b/src/main/java/com/unitedcoder/classconcepts/package1/Alpha.java deleted file mode 100644 index 572213c..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package1/Alpha.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.unitedcoder.classconcepts.package1; - -public class Alpha { - public static void main(String[] args) { - Alpha a = new Alpha(); - a.info = "Alpha class"; - System.out.println(a.info); -} - - private String info; - - public Alpha() { - } - - public Alpha(String info) { - this.info = info; - } - - protected String getInfo() { - return info; - } - - protected void setInfo(String info) { - this.info = info; - } - - void alphaTest() { - System.out.println("Alpha test access"); - - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/package1/Beta.java b/src/main/java/com/unitedcoder/classconcepts/package1/Beta.java deleted file mode 100644 index c368bda..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package1/Beta.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.unitedcoder.classconcepts.package1; - -public class Beta { - public static void main(String[] args) { - Alpha a1=new Alpha(); - a1.setInfo("Alpha"); - System.out.println(a1.getInfo()); - a1.alphaTest(); - } - private String version; - - public Beta() { - } - - public Beta(String version) { - this.version = version; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - -} diff --git a/src/main/java/com/unitedcoder/classconcepts/package1/Student.java b/src/main/java/com/unitedcoder/classconcepts/package1/Student.java deleted file mode 100644 index f159cbb..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package1/Student.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.unitedcoder.classconcepts.package1; - -public class Student { - private String firstName; - private String lastName; - private String gender; - - public Student() { - } - - public Student(String firstName, String lastName, String gender) { - this.firstName = firstName; - this.lastName = lastName; - this.gender = gender; - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - - public String getGender() { - return gender; - } -} diff --git a/src/main/java/com/unitedcoder/classconcepts/package1/StudentPrintDemo1.java b/src/main/java/com/unitedcoder/classconcepts/package1/StudentPrintDemo1.java deleted file mode 100644 index fcfe07b..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package1/StudentPrintDemo1.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.unitedcoder.classconcepts.package1; - -public class StudentPrintDemo1 { - public static void main(String[] args) { - Student student = new Student("Tom", "Mike", "Male"); - System.out.println(student.getFirstName()); - System.out.println(student.getLastName()); - System.out.println(student.getGender()); - } - } diff --git a/src/main/java/com/unitedcoder/classconcepts/package2/AlphaSub.java b/src/main/java/com/unitedcoder/classconcepts/package2/AlphaSub.java deleted file mode 100644 index 92fd318..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package2/AlphaSub.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.unitedcoder.classconcepts.package2; - -import com.unitedcoder.classconcepts.package1.Alpha; - -public class AlphaSub extends Alpha { - //alpha class- paren class alphasub--child class - public static void main(String[] args) { - AlphaSub sub = new AlphaSub(); - sub.setInfo("Alpha class"); - System.out.println(sub.getInfo()); - } - - } diff --git a/src/main/java/com/unitedcoder/classconcepts/package2/Gamma.java b/src/main/java/com/unitedcoder/classconcepts/package2/Gamma.java deleted file mode 100644 index 3b09989..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package2/Gamma.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.unitedcoder.classconcepts.package2; - -import com.unitedcoder.classconcepts.package1.Alpha; - -public class Gamma { - public static void main(String[] args) { - Alpha a2=new Alpha(); - - } - private String name; - - public Gamma() { - } - - public Gamma(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} - - diff --git a/src/main/java/com/unitedcoder/classconcepts/package2/StudentPrintDemo2.java b/src/main/java/com/unitedcoder/classconcepts/package2/StudentPrintDemo2.java deleted file mode 100644 index 41553e3..0000000 --- a/src/main/java/com/unitedcoder/classconcepts/package2/StudentPrintDemo2.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.unitedcoder.classconcepts.package2; - -import com.unitedcoder.classconcepts.package1.Student; - -public class StudentPrintDemo2 { - public static void main(String[] args) { - Student student=new Student("David","Smith","Male"); - System.out.println(student.getFirstName()); - System.out.println(student.getLastName()); - System.out.println(student.getGender()); - } -} diff --git a/src/main/java/com/unitedcoder/configutility/ApplicationConfig.java b/src/main/java/com/unitedcoder/configutility/ApplicationConfig.java deleted file mode 100644 index 18771a6..0000000 --- a/src/main/java/com/unitedcoder/configutility/ApplicationConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.unitedcoder.configutility; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; - -public class ApplicationConfig { - //write a method to read a specific key value pair from config file - public static String readConfigProperties(String fileName,String key){ - Properties prop=new Properties(); - String workingDirectory=System.getProperty("user.dir"); - String value; - try { - prop.load(new FileInputStream(workingDirectory+ File.separator+fileName)); - } catch (IOException e) { - e.printStackTrace(); - } - value=prop.getProperty(key); - System.out.println(String.format("%s=%s",key,value)); - return value; - } -} diff --git a/src/main/java/com/unitedcoder/configutility/ConfigDemo.java b/src/main/java/com/unitedcoder/configutility/ConfigDemo.java deleted file mode 100644 index 605d880..0000000 --- a/src/main/java/com/unitedcoder/configutility/ConfigDemo.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.unitedcoder.configutility; - -public class ConfigDemo { - public static void main(String[] args) { - String configFile="config.txt"; - ApplicationConfig.readConfigProperties(configFile,"produrl"); - ApplicationConfig.readConfigProperties(configFile,"qaurl"); - ApplicationConfig.readConfigProperties(configFile,"username"); - ApplicationConfig.readConfigProperties(configFile,"password"); - ApplicationConfig.readConfigProperties(configFile,"timeout"); - ApplicationConfig.readConfigProperties(configFile,"login"); - - - - - } -} diff --git a/src/main/java/com/unitedcoder/configutility/CubeCartConfigTest.java b/src/main/java/com/unitedcoder/configutility/CubeCartConfigTest.java deleted file mode 100644 index cb3ee13..0000000 --- a/src/main/java/com/unitedcoder/configutility/CubeCartConfigTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.unitedcoder.configutility; - -import com.unitedcoder.classconcepts.LoginUser; -import com.unitedcoder.io.FileUtility; -import org.apache.commons.io.FileUtils; -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -import java.io.File; -import java.io.IOException; - -public class CubeCartConfigTest { - public static void main(String[] args) { - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - ChromeOptions options = new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver = new ChromeDriver(options); - driver.manage().window().maximize(); - String url; - String configFile="config.properties"; - if(Integer.parseInt(ApplicationConfig.readConfigProperties(configFile,"qa"))==1){ - url=ApplicationConfig.readConfigProperties(configFile,"qaurl"); - } - else{ - url=ApplicationConfig.readConfigProperties(configFile,"produrl"); - } - driver.get(url); - UiUtility utility=new UiUtility(driver); - WebElement userNameField=driver.findElement(By.id("username")); - String userName=ApplicationConfig.readConfigProperties(configFile,"username"); - utility.waitForElementPresent(userNameField); - userNameField.sendKeys(userName); - WebElement passwordField=driver.findElement(By.id("password")); - String password=ApplicationConfig.readConfigProperties(configFile,"password"); - utility.waitForElementPresent(passwordField); - passwordField.sendKeys(password); - WebElement loginButton=driver.findElement(By.id("login")); - utility.waitForElementPresent(loginButton); - loginButton.click(); - WebElement logOutIcon=driver.findElement(By.cssSelector("i.fa.fa-sign-out")); - StringBuilder result=new StringBuilder(); - FileUtility fileUtility=new FileUtility(); - if(logOutIcon.isDisplayed()){ - result.append("Login successfully"); - utility.takeScreenShot("loginsuccess.png"); - } - fileUtility.writeToFile("test-Result","cubecart-result", - ".txt",result.toString()); - utility.waitForElementPresent(logOutIcon); - logOutIcon.click(); - WebElement loginButtonAfterLogOut=driver.findElement(By.id("login")); - utility.waitForElementPresent(loginButtonAfterLogOut); - if(loginButtonAfterLogOut.isDisplayed()){ - result.append("Log Out Successfully"); - utility.takeScreenShot("logousuccess.png"); - } - File existingFile=new File("test-Result"+File.separator+"cubecart-result.txt"); - try { - FileUtils.writeStringToFile(existingFile,result.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/com/unitedcoder/configutility/GoogleSearchScreenShot.java b/src/main/java/com/unitedcoder/configutility/GoogleSearchScreenShot.java deleted file mode 100644 index 0fab9b1..0000000 --- a/src/main/java/com/unitedcoder/configutility/GoogleSearchScreenShot.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.unitedcoder.configutility; - -import org.openqa.selenium.*; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -public class GoogleSearchScreenShot { - public static void main(String[] args) { - //define chrome driver location - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - ChromeOptions options=new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver=new ChromeDriver(options); - //maximize the browser - driver.manage().window().maximize(); - //open google site - driver.get("https://www.google.com"); - //find search box element - String[] searchWords=new String[]{"Turkey","Japan","Dubai","Finland","Amesterdam"}; - UiUtility utility=new UiUtility(driver); - for(String words:searchWords) { - WebElement searchBox = driver.findElement(By.name("q")); - searchBox.sendKeys(words + Keys.ENTER); - utility.takeScreenShot(words+".png"); - driver.navigate().back(); - } - driver.close(); - driver.quit(); - - } -} diff --git a/src/main/java/com/unitedcoder/configutility/TestConfig.java b/src/main/java/com/unitedcoder/configutility/TestConfig.java deleted file mode 100644 index 5a9e193..0000000 --- a/src/main/java/com/unitedcoder/configutility/TestConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.unitedcoder.configutility; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -public class TestConfig { - public static void main(String[] args) throws IOException { - Properties properties=new Properties(); - FileInputStream inputStream=new FileInputStream("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\config.properties"); - properties.load(inputStream); - System.out.println(properties.getProperty("qaurl")); - System.out.println("befor change: "+properties.getProperty("qa")); - properties.setProperty("qa","2"); - System.out.println("After change: "+properties.getProperty("qa")); - FileOutputStream outputStream=new FileOutputStream("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\config.properties"); - properties.store(outputStream,null); - } -} diff --git a/src/main/java/com/unitedcoder/configutility/UiUtility.java b/src/main/java/com/unitedcoder/configutility/UiUtility.java deleted file mode 100644 index fbc49ae..0000000 --- a/src/main/java/com/unitedcoder/configutility/UiUtility.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.unitedcoder.configutility; - -import org.apache.commons.io.FileUtils; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.io.File; -import java.io.IOException; - -public class UiUtility { - private int timeout=Integer.parseInt(ApplicationConfig - .readConfigProperties("config.properties","timeout")); - private WebDriver driver; - public UiUtility(WebDriver driver){ - this.driver=driver; - } - public void waitForElementPresent(WebElement element){ - WebDriverWait wait=new WebDriverWait(driver,timeout); - wait.until(ExpectedConditions.visibilityOf(element)); - } - - public void takeScreenShot(String fileName){ - TakesScreenshot screenshot=(TakesScreenshot)driver; - File screenShotFile=screenshot.getScreenshotAs(OutputType.FILE); - String folder=ApplicationConfig.readConfigProperties("config.properties", - "imagefolder"); - File finalFile=new File(folder+File.separator+fileName); - try { - FileUtils.copyFile(screenShotFile,finalFile); - } catch (IOException e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/com/unitedcoder/csv/AmazonSearchWithCSV.java b/src/main/java/com/unitedcoder/csv/AmazonSearchWithCSV.java deleted file mode 100644 index 46b17c4..0000000 --- a/src/main/java/com/unitedcoder/csv/AmazonSearchWithCSV.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.unitedcoder.csv; - -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import java.util.List; - -public class AmazonSearchWithCSV { - public static void main(String[] args) { - CSVFileUtility csvFileUtility=new CSVFileUtility(); - List searchWords=csvFileUtility.readCSVFile("test-Result","amazon-products.csv", - "search words"); - System.out.println(searchWords.toString()); - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver = new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - //open google site - driver.get("https://www.amazon.com"); - for (String keyWords : searchWords) { - WebElement serachBox = driver.findElement(By.id("twotabsearchtextbox")); - serachBox.sendKeys(keyWords+ Keys.ENTER); - driver.navigate().back(); - } - driver.close(); - driver.quit(); - } -} diff --git a/src/main/java/com/unitedcoder/csv/CSVFileReader.java b/src/main/java/com/unitedcoder/csv/CSVFileReader.java deleted file mode 100644 index d3e1170..0000000 --- a/src/main/java/com/unitedcoder/csv/CSVFileReader.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.unitedcoder.csv; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVRecord; - -import java.io.*; - -public class CSVFileReader { - public static void main(String[] args) { - Reader reader=null; - try { - reader=new FileReader("test-Result"+ File.separator+"login.csv"); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - Iterable records=null; - try { - records= CSVFormat.RFC4180.withHeader("username","password","phonenumber","mail").parse(reader); - } catch (IOException e) { - e.printStackTrace(); - } - for(CSVRecord record:records){ - String username=record.get("username"); - String password=record.get("password"); - String phone=record.get("phonenumber"); - String mail=record.get("mail"); - System.out.println(String.format("%s %s %s %s",username,password,phone,mail)); - } - } -} diff --git a/src/main/java/com/unitedcoder/csv/CSVFileUtility.java b/src/main/java/com/unitedcoder/csv/CSVFileUtility.java deleted file mode 100644 index 7c04626..0000000 --- a/src/main/java/com/unitedcoder/csv/CSVFileUtility.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.unitedcoder.csv; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVRecord; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -public class CSVFileUtility { - public List readCSVFile(String filePath,String fileName,String headerName) { - List values=new ArrayList<>(); - Reader reader=null; - try { - reader=new FileReader(filePath+ File.separator+fileName); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - Iterable records=null; - try { - records= CSVFormat.RFC4180.withFirstRecordAsHeader().withHeader(headerName).parse(reader); - } catch (IOException e) { - e.printStackTrace(); - } - for(CSVRecord record:records){ - String contents=record.get(headerName); - values.add(contents); - System.out.println(String.format("search word %s",contents)); - } - return values; - } -} diff --git a/src/main/java/com/unitedcoder/csv/CSVWriteDemo.java b/src/main/java/com/unitedcoder/csv/CSVWriteDemo.java deleted file mode 100644 index 5f489d1..0000000 --- a/src/main/java/com/unitedcoder/csv/CSVWriteDemo.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.unitedcoder.csv; - -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; - -public class CSVWriteDemo { - public static void main(String[] args) { - StringBuilder builder=new StringBuilder(); - builder.append("TestID,TestModule,TestType,TestStatus").append("\n"); - builder.append("1,Customer,regression,Pass").append("\n"); - builder.append("2,Inventory,regression,Pass").append("\n"); - builder.append("3,Category,Smoke,Failed"); - File file=new File("test-Result"+File.separator+"test-result.csv"); - try { - FileUtils.writeStringToFile(file,builder.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/CategoryPage.java b/src/main/java/com/unitedcoder/cubecartautomation/CategoryPage.java deleted file mode 100644 index cbfe3a4..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/CategoryPage.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -public class CategoryPage extends TestBase { - public boolean addCategory(){ - WebElement categoryLink=driver.findElement(By.id("nav_categories")); - waitForElementPresent(categoryLink,10); - categoryLink.click(); - WebElement addCatogoryLink=driver.findElement(By.linkText("Add Category")); - waitForElementPresent(addCatogoryLink,10); - addCatogoryLink.click(); - WebElement nameTextField=driver.findElement(By.id("name")); - waitForElementPresent(nameTextField,5); - nameTextField.sendKeys("Java-Selenium"+System.currentTimeMillis()); - WebElement saveButton=driver.findElement(By.id("cat_save")); - waitForElementPresent(saveButton,5); - saveButton.click(); - WebElement successfulMessage=driver.findElement(By.cssSelector("div.success")); - if(successfulMessage.isDisplayed()){ - System.out.println("A product category is added successfully"); - System.out.println("Test passed"); - return true; - } - else{ - System.out.println("Product category test failed"); - return false; - } - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/DashBoardPage.java b/src/main/java/com/unitedcoder/cubecartautomation/DashBoardPage.java deleted file mode 100644 index b9be217..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/DashBoardPage.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -public class DashBoardPage extends TestBase { - public void logOut(){ - WebElement logOutBUtton=driver.findElement(By.cssSelector("i.fa.fa-sign-out")); - waitForElementPresent(logOutBUtton,5); - logOutBUtton.click(); - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/LoginPage.java b/src/main/java/com/unitedcoder/cubecartautomation/LoginPage.java deleted file mode 100644 index b031485..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/LoginPage.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import com.unitedcoder.classconcepts.LoginUser; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - - - -public class LoginPage extends TestBase { - - public void login(LoginUser user){ - driver.get(""); - WebElement userNameField=driver.findElement(By.id("username")); - waitForElementPresent(userNameField,5); - userNameField.sendKeys(user.getUserName()); - WebElement passwordField=driver.findElement(By.id("password")); - waitForElementPresent(passwordField,6); - passwordField.sendKeys(user.getPassWord()); - WebElement loginButton=driver.findElement(By.id("login")); - waitForElementPresent(loginButton,3); - loginButton.click(); - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/ProductPage.java b/src/main/java/com/unitedcoder/cubecartautomation/ProductPage.java deleted file mode 100644 index 1006092..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/ProductPage.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import com.unitedcoder.classconcepts.ProductContent; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; - -public class ProductPage extends TestBase { - public boolean addProduct(){ - WebElement productsLink=driver.findElement(By.id("nav_products")); - waitForElementPresent(productsLink,5); - productsLink.click(); - WebElement addProductLink=driver.findElement(By.xpath("//*[text()='Add Product']")); - waitForElementPresent(addProductLink,5); - addProductLink.click(); - ProductContent content=new ProductContent("Aynigar"+System.currentTimeMillis(), - "pz7865"); - driver.findElement(By.id("name")).sendKeys(content.getProductName()); - driver.findElement(By.id("product_code")).sendKeys(content.getProductCode()); - WebElement dropDown=driver.findElement(By.id("condition")); - Select selectDropDown=new Select(dropDown); - selectDropDown.selectByValue("used"); - driver.findElement(By.xpath("//input[@value='Save']")).click(); - String successfulMessage=driver.findElement(By.xpath("//div[@id=\"gui_message\"]/div[2]")).getText(); - if(driver.getPageSource().contains(successfulMessage)) { - System.out.println("Product added successfully , test pass"); - return true; - } - else { - System.out.println("Product not added , test failed"); - return false; - } - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/TestBase.java b/src/main/java/com/unitedcoder/cubecartautomation/TestBase.java deleted file mode 100644 index b4851e3..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/TestBase.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.FluentWait; -import org.openqa.selenium.support.ui.Wait; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.util.NoSuchElementException; -import java.util.concurrent.TimeUnit; - -public class TestBase { - public static WebDriver driver; - public static String browserName = "chrome"; - - public static void initialzation() { - //singlton design pattern - if (driver == null) { - if (browserName.equalsIgnoreCase("chrome")) { - //switch (browserName){ - // case "chrome": - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - driver = new ChromeDriver(); - driver.manage().window().maximize(); - //break; - //case "firefox": - } else if (browserName.equalsIgnoreCase("firefox")) { - System.setProperty("webdriver.gecko.driver", "c:\\webdriver\\geckodriver.exe"); - driver = new FirefoxDriver(); - driver.manage().window().maximize(); - //break; - } - } - - } - - public static void closeBrowser() { - driver.quit(); - driver = null; - } - - //method for explicit wait - public void waitForElementPresent(WebElement element, int timeOut) { - WebDriverWait wait = new WebDriverWait(driver, timeOut); - wait.until(ExpectedConditions.visibilityOf(element)); - } - - public void fluentWait(WebElement element){ - Wait wait=new FluentWait<>(driver) - .withTimeout(10, TimeUnit.SECONDS) - .pollingEvery(2,TimeUnit.SECONDS) - .ignoring(NoSuchElementException.class); - wait.until(ExpectedConditions.visibilityOf(element)); - } - - public static void sleep(int seconds) { - - try { - Thread.sleep(seconds * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/com/unitedcoder/cubecartautomation/TestRunner.java b/src/main/java/com/unitedcoder/cubecartautomation/TestRunner.java deleted file mode 100644 index df13795..0000000 --- a/src/main/java/com/unitedcoder/cubecartautomation/TestRunner.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.unitedcoder.cubecartautomation; - -import com.unitedcoder.classconcepts.LoginUser; - -public class TestRunner extends TestBase { - public static void main(String[] args) { - initialzation(); - LoginPage loginPage=new LoginPage(); - LoginUser user=new LoginUser("testautomation","automation123!"); - loginPage.login(user); - CategoryPage categoryPage=new CategoryPage(); - categoryPage.addCategory(); - sleep(3); - ProductPage productPage=new ProductPage(); - productPage.addProduct(); - sleep(3); - DashBoardPage dashBoardPage=new DashBoardPage(); - dashBoardPage.logOut(); - closeBrowser(); - - } -} diff --git a/src/main/java/com/unitedcoder/datetime/JodaDateTime.java b/src/main/java/com/unitedcoder/datetime/JodaDateTime.java index d23b2b7..139597f 100644 --- a/src/main/java/com/unitedcoder/datetime/JodaDateTime.java +++ b/src/main/java/com/unitedcoder/datetime/JodaDateTime.java @@ -1,47 +1,2 @@ -package com.unitedcoder.datetime; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Period; -import org.joda.time.PeriodType; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; -import java.time.ZoneId; -import java.util.Set; - -public class JodaDateTime { - public static void main(String[] args) { - //define a new joda date time - DateTime date=new DateTime(); - System.out.println(date.toString()); - DateTimeFormatter formatter= DateTimeFormat.forPattern("yyyy-MM-dd-HH-mm-ss-SS"); - System.out.println(date.toString(formatter)); - - DateTime universalTime=new DateTime(DateTimeZone.UTC); - System.out.println("Universal Time "+universalTime); - DateTimeZone istanbulTimeZone=DateTimeZone.forID("Asia/Kashgar"); - DateTime istanbulTime=new DateTime(istanbulTimeZone); - System.out.println("Asia/Kashgar time is : "+istanbulTime); - Set timeZones= ZoneId.getAvailableZoneIds(); - for(String s:timeZones){ - System.out.println(s); - } - //day year month - System.out.println(universalTime.getDayOfMonth()); - System.out.println(universalTime.getMonthOfYear()); - System.out.println(universalTime.getYear()); - //get the day Name - DateTime.Property dayName=universalTime.dayOfWeek(); - System.out.println(dayName.getAsShortText()); - System.out.println(universalTime.plusDays(5)); - System.out.println(universalTime.minusDays(2)); - //get difference of two day - DateTime beginDate=new DateTime("2020-10-20");//test case created day - DateTime executeDate=new DateTime(); - Period period=new Period(beginDate,executeDate, PeriodType.days()); - Period period1=new Period(beginDate,executeDate,PeriodType.weeks()); - System.out.println("Total weeks: "+period1.getWeeks()); - System.out.println("Total days: "+period.getDays()); - } -} diff --git a/src/main/java/com/unitedcoder/excel/ExcelReadDemo.java b/src/main/java/com/unitedcoder/excel/ExcelReadDemo.java deleted file mode 100644 index 86ea059..0000000 --- a/src/main/java/com/unitedcoder/excel/ExcelReadDemo.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.unitedcoder.excel; - -import java.util.List; - -public class ExcelReadDemo { - public static void main(String[] args) { - ExcelUtility excelUtility=new ExcelUtility(); - excelUtility.readExcellCell("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",0,0); - excelUtility.readExcellCell("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",0,1); - excelUtility.readExcellCell("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",1,0); - excelUtility.readExcellCell("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",1,1); - List loginUser=excelUtility.readMultipleCellValue("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",1); - for(LoginInfo users:loginUser){ - System.out.println(String.format("username=%s password=%s",users.getUsername(), - users.getPassword())); - } - - - } -} diff --git a/src/main/java/com/unitedcoder/excel/ExcelReadDemo1.java b/src/main/java/com/unitedcoder/excel/ExcelReadDemo1.java deleted file mode 100644 index 80c2bb1..0000000 --- a/src/main/java/com/unitedcoder/excel/ExcelReadDemo1.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.unitedcoder.excel; - -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import java.io.FileInputStream; -import java.io.IOException; - -public class ExcelReadDemo1 { - public static void main(String[] args) throws IOException { - String filePath="C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\countries.xlsx"; - FileInputStream inputStream=new FileInputStream(filePath); - XSSFWorkbook workbook=new XSSFWorkbook(inputStream); - XSSFSheet sheet=workbook.getSheetAt(0); - //using for loop - int rowCount=sheet.getLastRowNum(); - int colCount=sheet.getRow(1).getLastCellNum(); - - for(int r=0;r<=rowCount;r++){ - XSSFRow rows=sheet.getRow(r); - for(int cell=0;cell getData(String productName) throws IOException { - String filePath="C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\productInfo.xlsx"; - FileInputStream inputStream=new FileInputStream(filePath); - XSSFWorkbook workbook=new XSSFWorkbook(inputStream); - int sheets=workbook.getNumberOfSheets(); - List productInfo=new ArrayList<>(); - for(int i=0;i rows=sheet.iterator(); - Row firstRow=rows.next(); - Iterator cell=firstRow.cellIterator(); - while (rows.hasNext()){ - Row r=rows.next(); - if(r.getCell(0).getStringCellValue().equalsIgnoreCase(productName)){ - Iterator c=r.cellIterator(); - while (c.hasNext()){ - Cell c1=c.next(); - if(c1.getCellTypeEnum()== CellType.STRING){ - productInfo.add(c1.getStringCellValue()); - }else{ - productInfo.add(NumberToTextConverter.toText(c1.getNumericCellValue())); - } - } - } - } - } - } - return productInfo; - } - - public static void main(String[] args) throws IOException { - ExcelReadDemo2 readDemo2=new ExcelReadDemo2(); - List productList=readDemo2.getData("Selenium Book"); - System.out.println(productList.toString()); - } -} diff --git a/src/main/java/com/unitedcoder/excel/ExcelUtility.java b/src/main/java/com/unitedcoder/excel/ExcelUtility.java deleted file mode 100644 index 4cc4843..0000000 --- a/src/main/java/com/unitedcoder/excel/ExcelUtility.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.unitedcoder.excel; - -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.FillPatternType; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.xssf.usermodel.*; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -public class ExcelUtility { - //write a method to read from excell cells - public String readExcellCell(String fileName,String sheetName,int rowNumber,int cellNumber){ - FileInputStream fileInputStream=null; - try { - fileInputStream=new FileInputStream(fileName); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - XSSFWorkbook workbook=null; - try { - workbook=new XSSFWorkbook(fileInputStream); - } catch (IOException e) { - e.printStackTrace(); - } - XSSFSheet sheet=workbook.getSheet(sheetName); - XSSFRow row=sheet.getRow(rowNumber); - String cellValue=null; - if(row==null){ - System.out.println("Empty Row ,no data in the excell sheet"); - }else{ - XSSFCell cell=row.getCell(cellNumber); - CellType cellType=cell.getCellType(); - switch (cellType){ - case NUMERIC: - cellValue=String.valueOf(cell.getNumericCellValue()); - System.out.println(cellValue); - break; - case STRING: - cellValue=cell.getStringCellValue(); - System.out.println(cellValue); - break; - } - } - return cellValue; - } - - public List readMultipleCellValue(String fileName,String sheetName,int startRow){ - FileInputStream fileInputStream=null; - try { - fileInputStream=new FileInputStream(fileName); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - XSSFWorkbook workbook=null; - try { - workbook=new XSSFWorkbook(fileInputStream); - } catch (IOException e) { - e.printStackTrace(); - } - XSSFSheet sheet=workbook.getSheet(sheetName); - int rowCount=sheet.getLastRowNum(); - System.out.println("Last row Number is : "+rowCount); - List loginUser=new ArrayList<>(); - for(int r=startRow;r<=rowCount;r++){ - XSSFRow row=sheet.getRow(r); - if(row==null){ - System.out.println("Empty Row"); - } - else{ - XSSFCell usernameCell=row.getCell(0); - XSSFCell passwordCell=row.getCell(1); - loginUser.add(new LoginInfo(usernameCell.getStringCellValue(), - passwordCell.getStringCellValue())); - } - } - System.out.println(loginUser.toString()); - return loginUser; - } - - public void writeToExcelMultipleCells(String fileName,String sheetName,List contents){ - //define a file to write - File excelFile=new File(fileName); - //define a work book - XSSFWorkbook workbook=new XSSFWorkbook(); - //add sheet to the work book - XSSFSheet sheet=workbook.createSheet(sheetName); - //define row(s) in the work sheet - int numberOfRows=contents.size(); - for(int rowNumber=0;rowNumber testReport=new ArrayList<>(); - testReport.add("testName,testModule,testStaus,executesAt,executedBy"); - testReport.add("Login,Login,Passed,2020-12-12,Aynigar"); - testReport.add("Add Product,Inventory,Passed,2020-12-10,Aynigar"); - testReport.add("LogOut,login-logout,Passed,2020-12-12,Aynigar"); - utility.writeToExcelMultipleCells(fileName,"Regression-Test", - testReport); - - } -} diff --git a/src/main/java/com/unitedcoder/excel/ExcelWriteDemo2.java b/src/main/java/com/unitedcoder/excel/ExcelWriteDemo2.java deleted file mode 100644 index 3ccc0fe..0000000 --- a/src/main/java/com/unitedcoder/excel/ExcelWriteDemo2.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.unitedcoder.excel; - -import java.util.ArrayList; -import java.util.List; - -public class ExcelWriteDemo2 { - public static void main(String[] args) { - ExcelUtility utility=new ExcelUtility(); - String fileName="testdata/userInfo.xlsx"; - List loginUser=new ArrayList<>(); - loginUser.add("testautomation,automation123!"); - loginUser.add("testautomation1,automation123!"); - loginUser.add("testautomation2,automation123!"); - utility.writeToExcelMultipleCells(fileName,"user-info",loginUser); - - } -} diff --git a/src/main/java/com/unitedcoder/excel/ExcelWriteDemo3.java b/src/main/java/com/unitedcoder/excel/ExcelWriteDemo3.java deleted file mode 100644 index bc85382..0000000 --- a/src/main/java/com/unitedcoder/excel/ExcelWriteDemo3.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.unitedcoder.excel; - -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -public class ExcelWriteDemo3 { - public static void main(String[] args) throws IOException { - Object studentInfo[][]={ - {"StudentID","Student Name","Score"}, - {10,"Tom",90}, - {11,"David",95}, - {12,"mike",99} - }; - XSSFWorkbook workbook=new XSSFWorkbook(); - XSSFSheet sheet=workbook.createSheet("Class-A"); - int rows=studentInfo.length; - int columCount=studentInfo[0].length; - for(int r=0;r loginUser=utility.readMultipleCellValue("C:\\Users\\Aynigar\\projects\\SeleniumJavaTests\\testdata\\login.xlsx", - "Sayfa1",1); - System.out.println(loginUser.size()); - String filePath="testdata\\cubecart-report2.xlsx"; - List testResult=new ArrayList<>(); - testResult.add("testcase,module,test data,result"); - for(LoginInfo users:loginUser){ - WebElement userNameField=driver.findElement(By.id("username")); - waitForElementPresent(driver,userNameField); - String username=users.getUsername(); - userNameField.sendKeys(username); - WebElement passwordField=driver.findElement(By.id("password")); - waitForElementPresent(driver,passwordField); - String password=users.getPassword(); - passwordField.sendKeys(password); - WebElement loginButton=driver.findElement(By.id("login")); - waitForElementPresent(driver,loginButton); - loginButton.click(); - WebElement productLink=driver.findElement(By.id("nav_products")); - if(productLink.isDisplayed()) { - System.out.println("Login test passed"); - testResult.add("Admin Login,Login," + username + password + ",Passed"); - } - else { - System.out.println("Login test failed"); - testResult.add("Admin Login,Login," + username + password + ",Failed"); - } - WebElement logOutIcon=driver.findElement(By.cssSelector("i.fa.fa-sign-out")); - waitForElementPresent(driver,logOutIcon); - logOutIcon.click(); - } - utility.writeToExcelMultipleCells(filePath,"cubecart-report",testResult); - driver.close(); - driver.quit(); - } - public static void waitForElementPresent(WebDriver driver,WebElement element){ - WebDriverWait wait=new WebDriverWait(driver,60); - wait.until(ExpectedConditions.visibilityOf(element)); - } -} diff --git a/src/main/java/com/unitedcoder/io/FileWriteDemo2.java b/src/main/java/com/unitedcoder/io/FileWriteDemo2.java index be3ed53..5ef151f 100644 --- a/src/main/java/com/unitedcoder/io/FileWriteDemo2.java +++ b/src/main/java/com/unitedcoder/io/FileWriteDemo2.java @@ -1,27 +1,14 @@ package com.unitedcoder.io; -import org.apache.commons.io.FileUtils; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; + import java.io.File; import java.io.IOException; public class FileWriteDemo2 { public static void main(String[] args) { - String content="Test Passed"; - content=content+"Test"; - //define timeStamp for the file - DateTime date=new DateTime(); - DateTimeFormatter formatter= DateTimeFormat.forPattern("yyyy-MM-dd-HH-mm-ss-SS"); - String timeStamp=date.toString(formatter); - String fileName="test"+timeStamp+".txt"; - File myFile=new File("test-result"+File.separator+fileName); - try { - FileUtils.writeStringToFile(myFile,content); - } catch (IOException e) { - e.printStackTrace(); - } + String content = "Test Passed"; + content = content + "Test"; + } -} +} \ No newline at end of file diff --git a/src/main/java/com/unitedcoder/json/RoleBasedSecurityTestWithJson.java b/src/main/java/com/unitedcoder/json/RoleBasedSecurityTestWithJson.java deleted file mode 100644 index 741ef1a..0000000 --- a/src/main/java/com/unitedcoder/json/RoleBasedSecurityTestWithJson.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.unitedcoder.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.unitedcoder.excel.ExcelUtility; -import com.unitedcoder.excel.LoginInfo; -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class RoleBasedSecurityTestWithJson { - public static void main(String[] args) { - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - ChromeOptions options = new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver = new ChromeDriver(options); - driver.manage().window().maximize(); - driver.get("http://cubecart.unitedcoderschool.com/ecommerce/admin_w4vqap.php?_g=customers&node=email"); - //for getting the sart time - TestResult testResult = new TestResult(); - String startTime = TestHelper.getToday() + " " + TestHelper.getCurrentTime(); - testResult.setTestStartTime(startTime); - //for current user - testResult.setTestExecutedBy(TestHelper.getCurrentUser()); - - ObjectMapper mapper = new ObjectMapper(); - Users loginUser = null; - try { - loginUser = mapper.readValue(new File("testdata\\users.json"), Users.class); - } catch (IOException e) { - e.printStackTrace(); - } - List testResultObjects = new ArrayList<>(); - List users = loginUser.getUsers(); - for (User user : users) { - TestResultObject testResultObject = new TestResultObject(); - if (user.getActive()) { - testResultObject.setTestModule("Login"); - testResultObject.setTestName("Login"); - - String testDate = TestHelper.getToday(); - testResultObject.setTestDate(testDate); - String testTime = TestHelper.getCurrentTime(); - testResultObject.setTestTime(testTime); - - WebElement userNameField = driver.findElement(By.id("username")); - waitForElementPresent(driver, userNameField); - String username = user.getUsername(); - userNameField.sendKeys(username); - WebElement passwordField = driver.findElement(By.id("password")); - waitForElementPresent(driver, passwordField); - String password = user.getPassword(); - passwordField.sendKeys(password); - WebElement loginButton = driver.findElement(By.id("login")); - waitForElementPresent(driver, loginButton); - loginButton.click(); - sleep(3); - WebElement productLink = driver.findElement(By.id("nav_products")); - if (productLink.isDisplayed()) { - System.out.println("Login test passed"); - testResultObject.setTestStatus(true); - } else { - System.out.println("Login test failed"); - testResultObject.setTestStatus(false); - } - WebElement logOutIcon = driver.findElement(By.cssSelector("i.fa.fa-sign-out")); - waitForElementPresent(driver, logOutIcon); - logOutIcon.click(); - sleep(5); - } - testResultObjects.add(testResultObject); - } - driver.close(); - driver.quit(); - testResult.setTestEndTime(TestHelper.getToday() + " " + TestHelper.getCurrentTime()); - testResult.setTestResultObjectList(testResultObjects); - ObjectMapper mapper1=new ObjectMapper(); - try { - mapper1.writeValue(new File("testdata\\login-test-result.json"),testResult); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void sleep(int second) { - try { - Thread.sleep(1000 * second); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public static void waitForElementPresent(WebDriver driver, WebElement element) { - WebDriverWait wait = new WebDriverWait(driver, 60); - wait.until(ExpectedConditions.visibilityOf(element)); - } -} diff --git a/src/main/java/com/unitedcoder/json/TestHelper.java b/src/main/java/com/unitedcoder/json/TestHelper.java index 5aa2364..4eaf4ef 100644 --- a/src/main/java/com/unitedcoder/json/TestHelper.java +++ b/src/main/java/com/unitedcoder/json/TestHelper.java @@ -1,22 +1,12 @@ package com.unitedcoder.json; + import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; + +import java.time.format.DateTimeFormatter; public class TestHelper { - public static String getToday(){ - DateTime dateTime=new DateTime(); - DateTimeFormatter formatter= DateTimeFormat.forPattern("yyyy-MM-dd"); - return dateTime.toString(formatter); - } - public static String getCurrentTime(){ - DateTime dateTime=new DateTime(); - DateTimeFormatter formatter= DateTimeFormat.forPattern("HH-mm-ss-SS"); - return dateTime.toString(formatter); - } - public static String getCurrentUser(){ - String currentUser=System.getProperty("user.name"); - return currentUser; - } -} + + + } \ No newline at end of file diff --git a/src/main/java/com/unitedcoder/studentshomework/amazonsearch/AmazonMultopleSearch.java b/src/main/java/com/unitedcoder/studentshomework/amazonsearch/AmazonMultopleSearch.java deleted file mode 100644 index 02e94fc..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/amazonsearch/AmazonMultopleSearch.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.unitedcoder.studentshomework.amazonsearch; - -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; - -public class AmazonMultopleSearch { - public static void main(String[] args) throws InterruptedException { - /*String[] products = new String[]{"iphone", "mac", "ipad"}; - Product product = new Product(); -*/ - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - WebDriver driver = new ChromeDriver(); - driver.manage().window().maximize(); - driver.get("https://www.amazon.com"); - - Product product = new Product(); - product.setProduct(new String[]{"iphone", "mac", "ipad"}); - int countBack =1; - for (String s: product.getProduct()){ - WebElement searchBox = driver.findElement(By.name("field-keywords")); - searchBox.sendKeys(s + Keys.ENTER); - Thread.sleep(1000); - if (countBack listOfRow=newsLetterTable.findElements(By.tagName("tr")); - JavascriptExecutor javascriptExecutor=(JavascriptExecutor)library.getDriver(); - for(int i=0;i= 6 && ay <= 8) { - System.out.println("ياز ئېيىغا تەۋە "); - } else if (ay >= 3 && ay <= 5) - System.out.println("باھار ئېيىغا تەۋە ، ئىشنىڭ بېشى باھاردىن دەپتىكەن كونىلار"); - - else if (ay >= 9 && ay <= 11) - System.out.println("بەركەتلىك كۈز ئېيىغا تەۋە"); - - else - System.out.println("ئەگەر سىز ھازىر قىش ئايلىرىدا بولغان بولسىڭىز ، قېلىنراق كېيىنىڭ"); - - - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork.java b/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork.java deleted file mode 100644 index 073942f..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.unitedcoder.studentshomework.week7day1; - -import org.apache.commons.lang3.StringUtils; - -import java.util.Scanner; - -public class TaxHomeWork { - public static void main(String[] args) { - Scanner input = new Scanner(System.in); - double tax=0; - System.out.println("Enter your annual salary: "); - String annualSalary = input.next(); - - if (StringUtils.isNumeric(annualSalary)) { - - int salary = Integer.parseInt(annualSalary); - System.out.println("Enter your tax filing status (single/married): "); - String taxFilingStatus = input.next(); - boolean single = taxFilingStatus.equalsIgnoreCase("single"); - boolean married = taxFilingStatus.equalsIgnoreCase("married"); - if (single || married) { - - if ((single && salary > 32000) || (married && salary > 64000)) { - System.out.printf("\nYour annual salary is %d$.\n"+ - "You are %s.\n", salary, taxFilingStatus.toLowerCase()); - //use switch for calculate tax - switch (taxFilingStatus.toLowerCase()){ - case "single": - tax = (32000*0.1)+(salary-32000)*0.25;//tax = salary*0.25-4800 - System.out.println("So you have to pay 10% tax for the $32,000 of your annual salary; pay 25% tax for the annual salary over $32,000."); - break; - case "married": - tax = (64000*0.1)+(salary-64000)*0.25;//tax = salary*0.25-9600 - System.out.println("So you have to pay 10% tax for the $64,000 of your annual salary; pay 25% tax for the annual salary over $64,000."); - } - System.out.printf("Thus your total tax is %.2f$.\n", tax); - } - if ((single && salary <= 32000) || (married && salary <= 64000)) { - tax = 0.1 * salary; - System.out.printf("\nYour annual salary is %d$.\n" + - "You are %s.\n" + - "So you have to pay 10%% tax for your annual salary.\n" + - "Thus your total tax is %.0f$.\n", salary, taxFilingStatus.toLowerCase(), tax); - - } - } - else - System.out.println("Control your spelling, type \"single\" or \"married\" " + - "(system is not case sensitive)."); - } - else - System.out.println("You should enter numeric type and the number you entered should not be minus."); - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork1.java b/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork1.java deleted file mode 100644 index 1c009e9..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week7day1/TaxHomeWork1.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.unitedcoder.studentshomework.week7day1; - -import java.util.Scanner; - -public class TaxHomeWork1 { - public static void main(String[] args) { - System.out.println("Please input your salary for the year to calculate your taxes: "); - Scanner input = new Scanner(System.in); - double annualSalary = input.nextDouble(); - System.out.println("You entered " + annualSalary); - System.out.println("please enter your status : " + "( plz enter single or married) "); - String status = input.next(); - double tax =0; - if (status.equalsIgnoreCase("single")&& annualSalary <= 32000) { // Salary less than or equal to 32k SINGLE 10% - tax = annualSalary * 0.1; - System.out.println("tax" + tax); - } else if (status.equalsIgnoreCase("single") && annualSalary > 32000) { // Salary more than 32k SINGLE 25% - tax = (annualSalary - 32000) * 0.25 + 32000 * 0.1; - System.out.println("tax" + tax); - } else if (status.equalsIgnoreCase("married") && annualSalary <= 64000) { // Salary less than or equal to 64k - tax = annualSalary * 0.1; - System.out.println("tax" + tax); - } else if (status.equalsIgnoreCase("married") && annualSalary > 64000) { //Salary more than 64k MARRIED 25% - tax = (annualSalary - 64000) * 0.25 + 64000 * 0.1; - System.out.println("tax" + tax); - } else - System.out.println("invalid status ,please just type single or married "); - - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber1.java b/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber1.java deleted file mode 100644 index a75f5eb..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber1.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.unitedcoder.studentshomework.week7day3; - -import java.util.Scanner; - -public class PrimeNumber1 { - public static void main(String[] args) { - Scanner input = new Scanner(System.in); - System.out.println("Please enter any integer number: "); - int number = input.nextInt(); - System.out.printf("Within %d, those are prime numbers: \n", number); - for(int i=2; i<=number;i++){ - int j; - for (j=2; j<=i;j++){ - if (i%j==0){ - break; - } - } - if(i==j){ - System.out.print(i + " "); - } - // 10/2 10/3 10/4 10/10 - - } - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber2.java b/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber2.java deleted file mode 100644 index 6736be3..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber2.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.unitedcoder.studentshomework.week7day3; - -import java.util.Scanner; - -public class PrimeNumber2 { - public static void main(String[] args) { - Scanner scanner=new Scanner(System.in); - int num=scanner.nextInt(); - int r=0; - for (int i = 2; i<=num; i++) { //all numbers - int j=2; - while (i>j) { - if (i%j==0) - break; //not a prime number,out of loop - j++; - } - if (j==i) { - System.out.print(i+ "\t"); - r++; //calculate the number of outputs - if (r%20==0) //After every 10 outputs, a line feed. - System.out.println(); - } - } - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber3.java b/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber3.java deleted file mode 100644 index e6fb56f..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week7day3/PrimeNumber3.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.unitedcoder.studentshomework.week7day3; - -import java.util.Scanner; - -public class PrimeNumber3 { - public static void main(String[] args) { - Scanner scanner=new Scanner(System.in); - System.out.println("Please enter any number between 0 and 500:"); - //Don't stop while entering the wrong number. - while (true) { - int number=scanner.nextInt(); - if (number >= 1 && number <= 500) { - System.out.println(String.format("Between 1 and 500, the numbers can be divisible by %d are : ",number)); - for (int i = 1; i <= 500; i++) { - if (i % number == 0) - System.out.printf(i + ","); - } - break; - - } else - System.out.println("The number you have entered is incorrect!!!\n Please enter a number between 1 and 500 :"); - } - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week8day2/CollectionProject.java b/src/main/java/com/unitedcoder/studentshomework/week8day2/CollectionProject.java deleted file mode 100644 index 92bfbae..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week8day2/CollectionProject.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.unitedcoder.studentshomework.week8day2; - -import java.util.ArrayList; -import java.util.Collections; - -public class CollectionProject { - public static void main(String[] args) { - ArrayList arr30 = new ArrayList(); - ArrayList arr100 = new ArrayList(); - int countEven = 0; - int countOdd = 0; - int count3 = 0; - int sum = 0; - for(int i = 0; i <100; i++){ - //0.0 --0.99 0--99 1-100 - int ran = (int)(Math.random()*100+1); - // The array that length of 100 - arr100.add(ran); - sum = sum + arr100.get(i); - // The array that length of 30 - if (i<30) { - arr30.add(ran); - //Even, Odd and the number divided by 3 counts - if (arr30.get(i) % 2 == 0) { - countEven++; - } - if(arr30.get(i)%2!=0) - countOdd++; - if (arr30.get(i) % 3 == 0) - count3++; - } - } - System.out.println(arr30); - System.out.println("Total even number is: "+ countEven); - System.out.println("Total Odd number is: "+ countOdd); - System.out.println("Total count of number that divided by 3 is: "+ count3); - System.out.println(String.format("\nSum of 100 random namber is: %d, average is: %d.", sum, sum/100)); - // sort by ascending order - Collections.sort(arr30); - Collections.sort(arr100); - System.out.println("100 random numbers ascending order:\n" + arr100); - System.out.println("30 random numbers ascending order:\n" + arr30); - //sort by descending order - for(int i= arr30.size()-1; i >=0; i--){ - System.out.print(arr30.get(i)+" "); - } - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week8day2/MaharaLoginLogout.java b/src/main/java/com/unitedcoder/studentshomework/week8day2/MaharaLoginLogout.java deleted file mode 100644 index 256e202..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week8day2/MaharaLoginLogout.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.unitedcoder.studentshomework.week8day2; - -import org.openqa.selenium.*; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -import java.util.ArrayList; -import java.util.List; - -public class MaharaLoginLogout { - public static void main(String[] args) throws InterruptedException { - System.setProperty("webdriver.chrome.driver", "c:/webdriver/chromedriver.exe"); - ChromeOptions options = new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver = new ChromeDriver(); - driver.manage().window().maximize(); - driver.get("https://demo.mahara.org/"); - Thread.sleep(3000); - List userNames = new ArrayList<>(); - userNames.add("admin"); - userNames.add("student"); - userNames.add("learner"); - userNames.add("staff"); - userNames.add("sitestaff"); - for (int i = 0; i < userNames.size(); i++) { - WebElement loginUser = driver.findElement(By.cssSelector("input[id='login_login_username']")); - loginUser.click(); - loginUser.sendKeys(userNames.get(i), Keys.TAB); - WebElement passWord = driver.findElement(By.xpath("//input[@id='login_login_password']")); - passWord.sendKeys("MaharaDemo"); - WebElement loginBtn = driver.findElement(By.id("login_submit")); - loginBtn.click(); - //WebElement message=driver.findElement(By.cssSelector("button[title='Administration menu']")); - WebElement acntMenu = driver.findElement(By.cssSelector("span[class='icon icon-chevron-down collapsed']")); - acntMenu.click(); - Thread.sleep(3000); - driver.findElement(By.xpath("//*[@id=\"logoutbutton\"]/span[2]")).click(); - } - Thread.sleep(3000); - WebElement verifMesg = driver.findElement(By.xpath("//div[contains(text(),'You have been logged out successfully')]")); - String sucsMesg = verifMesg.getText(); - System.out.println(sucsMesg); - - if (sucsMesg.equalsIgnoreCase("You have been logged out successfully")) {//verify if it is logout - System.out.println("User logged out"); - } else { - System.out.println("failed"); - } - driver.close(); - driver.quit(); - - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject.java b/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject.java deleted file mode 100644 index f7f8c45..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.unitedcoder.studentshomework.week8day2; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class MapProject { - public static void main(String[] args) { -/* Use Java Map data structure store following information. - Key Value - MD Maryland - VA Virginia - NY New York - Count the number of keys and print out the number - Use for each loop, print out the key and value of each state.*/ - Map cities = new HashMap<>(); - cities.put("MD", "Maryland"); - cities.put("VA", "Virginia"); - cities.put("NY", "New York"); - System.out.println("Number of keys is: " + cities.size()); - Set cityKey = cities.keySet(); - - for (String keys: cityKey) { - System.out.println(String.format("%s : %s", keys, cities.get(keys))); - } - - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject1.java b/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject1.java deleted file mode 100644 index 30d59ba..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week8day2/MapProject1.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.unitedcoder.studentshomework.week8day2; - -import java.util.HashMap; -import java.util.Map; - -public class MapProject1 { - public static void main(String[] args) { -/* -Write a Java program with the following requirements. -Use Java Map data structure store following information. -Key Value -MD Maryland -VA Virginia -NY New York -Count the number of keys and print out the number -Use for each loop, print out the key and value of each state. - */ - Map states=new HashMap<>(); - states.put("MD","Maryland"); - states.put("VA","Virginia"); - states.put("NY","New York"); - int countKey=0; - for (int i=0;i set=states.keySet(); - for (Map.Entry entry:states.entrySet()){ - System.out.println(entry.getKey()+":"+entry.getValue()); - } - - } -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week9/AddNewsLetter.java b/src/main/java/com/unitedcoder/studentshomework/week9/AddNewsLetter.java deleted file mode 100644 index 8e35b68..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week9/AddNewsLetter.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.unitedcoder.studentshomework.week9; - -public class AddNewsLetter { -} diff --git a/src/main/java/com/unitedcoder/studentshomework/week9/NewsLetterContent.java b/src/main/java/com/unitedcoder/studentshomework/week9/NewsLetterContent.java deleted file mode 100644 index ba65daf..0000000 --- a/src/main/java/com/unitedcoder/studentshomework/week9/NewsLetterContent.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.unitedcoder.studentshomework.week9; - -public class NewsLetterContent { - -} diff --git a/src/main/java/com/unitedcoder/uiautomation/AmazonSearch.java b/src/main/java/com/unitedcoder/uiautomation/AmazonSearch.java deleted file mode 100644 index 93f6dba..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/AmazonSearch.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.apache.commons.lang3.time.StopWatch; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class AmazonSearch { - public static void main(String[] args) { - - //System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver = new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - //open google site - driver.get("https://www.amazon.com"); - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - //multiple product search iphone ipad sumsung - //String[] products = {"Iphone", "Ipad", "Sumsung", "Mac"}; - List products=new ArrayList<>(); - products.add("Iphone"); - products.add("Ipad"); - products.add("Mac"); - StopWatch watch=new StopWatch(); - watch.start(); - for (String keyWords : products) { - WebElement serachBox = driver.findElement(By.id("twotabsearchtextbox")); - serachBox.sendKeys(keyWords+ Keys.ENTER); - driver.navigate().back(); - } - watch.stop(); - System.out.println(watch); - driver.close(); - driver.quit(); - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/AmazonSearch1.java b/src/main/java/com/unitedcoder/uiautomation/AmazonSearch1.java deleted file mode 100644 index 344dca6..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/AmazonSearch1.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.unitedcoder.uiautomation; - -import com.unitedcoder.configutility.UiUtility; -import org.joda.time.DateTime; -import org.joda.time.Period; -import org.joda.time.PeriodType; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; - -import java.util.ArrayList; -import java.util.List; - -public class AmazonSearch1 { - public static void main(String[] args) { - System.setProperty("webdriver.chrome.driver", "c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver = new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - //open google site - DateTime browserOpenedTime=new DateTime(); - driver.get("https://www.amazon.com"); - //multiple product search iphone ipad sumsung - //String[] products = {"Iphone", "Ipad", "Sumsung", "Mac"}; - List products=new ArrayList<>(); - products.add("Iphone"); - products.add("Ipad"); - products.add("Mac"); - UiUtility utility=new UiUtility(driver); - for (String keyWords : products) { - WebElement serachBox = driver.findElement(By.id("twotabsearchtextbox")); - serachBox.sendKeys(keyWords+ Keys.ENTER); - utility.takeScreenShot(keyWords+".png"); - driver.navigate().back(); - } - driver.close(); - driver.quit(); - DateTime testEndTime=new DateTime(); - Period period=new Period(browserOpenedTime,testEndTime, PeriodType.seconds()); - System.out.println("Total test time is : "+period.getSeconds()); - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/FlightSite.java b/src/main/java/com/unitedcoder/uiautomation/FlightSite.java deleted file mode 100644 index 39ee1ea..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/FlightSite.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -public class FlightSite { - public static void main(String[] args) throws InterruptedException { - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - ChromeOptions options=new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver=new ChromeDriver(options); - driver.manage().window().maximize(); - driver.get(""); - WebElement passengersDropDown=driver.findElement(By.id("divpaxinfo")); - passengersDropDown.click(); - Thread.sleep(3000); - for(int i=0;i<5;i++) { - Thread.sleep(3000); - WebElement adultPlusIcon = driver.findElement(By.id("hrefIncAdt")); - adultPlusIcon.click(); - } - driver.close(); - driver.quit(); - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch.java b/src/main/java/com/unitedcoder/uiautomation/GoogleSearch.java deleted file mode 100644 index 6e09ea8..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.openqa.selenium.*; -import org.openqa.selenium.chrome.ChromeDriver; - -public class GoogleSearch { - public static void main(String[] args) { - //define chrome driver location - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver=new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - Dimension dimension=new Dimension(500,500); - //set browser window size - driver.manage().window().setSize(dimension); - //set browser location - Point point=new Point(300,200); - driver.manage().window().setPosition(point); - //open google site - driver.get("https://www.google.com"); - driver.close();// close current browser - driver.quit();//close all driver instance --system memory - - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch1.java b/src/main/java/com/unitedcoder/uiautomation/GoogleSearch1.java deleted file mode 100644 index d792b20..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch1.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; - -public class GoogleSearch1 { - public static void main(String[] args) throws InterruptedException { - //define chrome driver location - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver=new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - - //open google site - driver.get("https://www.google.com"); - //find search box element - WebElement searchBox=driver.findElement(By.name("q")); - searchBox.sendKeys(args[1]+ Keys.ENTER);//hard coded value - Thread.sleep(3000); - WebElement searchResult=driver.findElement(By.id("result-stats")); - if(searchResult.isDisplayed()){ - System.out.println("Google search test pass"); - } - else - System.out.println("Test faile"); - driver.close(); - driver.quit(); - - - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch2.java b/src/main/java/com/unitedcoder/uiautomation/GoogleSearch2.java deleted file mode 100644 index 5e68ce6..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch2.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.openqa.selenium.*; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -public class GoogleSearch2 { - public static void main(String[] args) { - //define chrome driver location - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - ChromeOptions options=new ChromeOptions(); - options.setPageLoadStrategy(PageLoadStrategy.NORMAL); - WebDriver driver=new ChromeDriver(options); - //maximize the browser - driver.manage().window().maximize(); - //open google site - driver.get("https://www.google.com"); - //find search box element - //driver.findElement(By.linkText("English")).click(); - WebElement searchBox = driver.findElement(By.name("q")); - searchBox.sendKeys("Java" + Keys.ENTER); - WebElement searchResult = driver.findElement(By.id("result-stats")); - String resultText=searchResult.getText(); - //String resultText="Yaklaşık 761.000.000 sonuç bulundu (0,37 saniye)"; - System.out.println(resultText); - int beginIndex=resultText.indexOf("("); - resultText=resultText.substring(0,beginIndex-1); - resultText=resultText.replace("Yaklaşık","") - .replace("sonuç bulundu","").trim(); - resultText=resultText.replace(".",""); - if(Integer.parseInt(resultText)>=100000){ - System.out.println("Test passed"); - }else - System.out.println("Test failed"); - - System.out.println(resultText); - driver.close(); - driver.quit(); - - } -} diff --git a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch3.java b/src/main/java/com/unitedcoder/uiautomation/GoogleSearch3.java deleted file mode 100644 index 8d07202..0000000 --- a/src/main/java/com/unitedcoder/uiautomation/GoogleSearch3.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.unitedcoder.uiautomation; - -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; - -public class GoogleSearch3 { - public static void main(String[] args) { - //define chrome driver location - System.setProperty("webdriver.chrome.driver","c:\\webdriver\\chromedriver.exe"); - //define chrome driver object instance - WebDriver driver=new ChromeDriver(); - //maximize the browser - driver.manage().window().maximize(); - //open google site - driver.get("https://www.google.com"); - //find search box element - for(int i=0;i<4;i++) { - WebElement searchBox = driver.findElement(By.name("q")); - searchBox.sendKeys(args[i] + Keys.ENTER); - driver.navigate().back(); - - } - driver.close(); - driver.quit(); - - } -} diff --git a/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java b/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java index 5d1c8af..92b526a 100644 --- a/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java +++ b/src/test/java/pageobjectdesignpattern/FunctionsLibrary.java @@ -28,7 +28,7 @@ public void sleep(int seconds){ } } public void waitForElementPresent(WebElement element){ - WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds((6)).getSeconds()); + WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds(6)); wait.until(ExpectedConditions.visibilityOf(element)); } From e2711496490a26467cf8dfd8a78872a1febf8cb5 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Thu, 14 Nov 2024 11:36:55 +0100 Subject: [PATCH 06/35] mahara login --- src/test/java/pageobjectdesignpattern/AddCustomerTest.java | 2 +- src/test/java/pageobjectdesignpattern/LoginPage.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java index 478389b..a7dfc09 100644 --- a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java +++ b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java @@ -23,7 +23,7 @@ public void setUp(){ } @Test public void addCustomerTest(){ - loginPage.login("admin","maharademo"); + loginPage.login("admin","MaharaDemo"); dashboardPage.clickCustomerListLink(); customerListPage.addCustomer("mr","ali","alim","asd@email.com"); Assertions.assertTrue(customerListPage.verifyCustomerAdded()); diff --git a/src/test/java/pageobjectdesignpattern/LoginPage.java b/src/test/java/pageobjectdesignpattern/LoginPage.java index dda06cd..a0ac6f8 100644 --- a/src/test/java/pageobjectdesignpattern/LoginPage.java +++ b/src/test/java/pageobjectdesignpattern/LoginPage.java @@ -14,11 +14,11 @@ public class LoginPage{ ChromeDriver driver; FunctionsLibrary functionsLibrary; - @FindBy(id = "username") + @FindBy(id = "login_login_username") WebElement userNameField; - @FindBy(id = "password") + @FindBy(id = "login_login_password") WebElement passwordField; - @FindBy(id = "login") + @FindBy(id = "login_submit") WebElement loginButton; public LoginPage(ChromeDriver driver) { From f0d316e36f423f0a9d5112a19b105ae8e5e19f83 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Thu, 14 Nov 2024 11:43:28 +0100 Subject: [PATCH 07/35] mahara login --- .idea/workspace.xml | 115 +++--------------- .../pageobjectdesignpattern/LoginPage.java | 1 + 2 files changed, 15 insertions(+), 101 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4090204..b993881 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,96 +4,8 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - @@ -259,13 +171,6 @@ @@ -630,7 +542,8 @@ - diff --git a/src/test/java/pageobjectdesignpattern/LoginPage.java b/src/test/java/pageobjectdesignpattern/LoginPage.java index a0ac6f8..333aa83 100644 --- a/src/test/java/pageobjectdesignpattern/LoginPage.java +++ b/src/test/java/pageobjectdesignpattern/LoginPage.java @@ -16,6 +16,7 @@ public class LoginPage{ FunctionsLibrary functionsLibrary; @FindBy(id = "login_login_username") WebElement userNameField; + @FindBy(id = "login_login_password") WebElement passwordField; @FindBy(id = "login_submit") From 8d93be0ab947ea70cbbdac4a2a9f30023e73b009 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Thu, 14 Nov 2024 11:50:08 +0100 Subject: [PATCH 08/35] mahara login --- src/test/java/pageobjectdesignpattern/LoginPage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/pageobjectdesignpattern/LoginPage.java b/src/test/java/pageobjectdesignpattern/LoginPage.java index 333aa83..30124d4 100644 --- a/src/test/java/pageobjectdesignpattern/LoginPage.java +++ b/src/test/java/pageobjectdesignpattern/LoginPage.java @@ -24,6 +24,7 @@ public class LoginPage{ public LoginPage(ChromeDriver driver) { this.driver = driver; + PageFactory.initElements(driver,this); functionsLibrary=new FunctionsLibrary(driver); } From 8dc2f0557084c5bb746021b1bac6fea45966238c Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Mon, 18 Nov 2024 12:52:14 +0100 Subject: [PATCH 09/35] mahara login --- .idea/workspace.xml | 41 +++++++------ .../AddCustomerTest.java | 32 +++++++--- .../pageobjectdesignpattern/BaseClass.java | 4 +- .../CustomerListPage.java | 59 ++++++++++++------- .../DashboardPage.java | 19 +++--- .../pageobjectdesignpattern/LoginPage.java | 16 ++++- 6 files changed, 113 insertions(+), 58 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b993881..e2ee401 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,11 @@ + + + + + - - - + + + + - + - + + - diff --git a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java index a7dfc09..c0b67d6 100644 --- a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java +++ b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java @@ -23,13 +23,27 @@ public void setUp(){ } @Test public void addCustomerTest(){ - loginPage.login("admin","MaharaDemo"); - dashboardPage.clickCustomerListLink(); - customerListPage.addCustomer("mr","ali","alim","asd@email.com"); - Assertions.assertTrue(customerListPage.verifyCustomerAdded()); - } - @AfterEach - public void tearDown(){ - closeBrowser(); - } + loginPage.login("standard_user","secret_sauce"); + + customerListPage.addToCart.click(); + customerListPage.addToCart1.click(); + customerListPage.shopingCar.click(); + customerListPage.checkOut.click(); + customerListPage.firstNameField.sendKeys("Ismet"); + customerListPage.lastNameField.sendKeys("Samsaq"); + customerListPage.zipCodeField.sendKeys("2840"); + customerListPage.Continue.click(); + customerListPage.Finish.click(); + customerListPage.verifyCustomerAdded(); + // customerListPage.addCustomer("mr","ali","alim","asd@email.com"); + Assertions.assertTrue(customerListPage.verifyCustomerAdded()); + dashboardPage.dropLink(); + dashboardPage.logOut(); + } + + // @AfterEach + //public void tearDown(){ + //closeBrowser(); + // } + } diff --git a/src/test/java/pageobjectdesignpattern/BaseClass.java b/src/test/java/pageobjectdesignpattern/BaseClass.java index 274bd01..b8306ce 100644 --- a/src/test/java/pageobjectdesignpattern/BaseClass.java +++ b/src/test/java/pageobjectdesignpattern/BaseClass.java @@ -9,11 +9,11 @@ **/ public class BaseClass { - ChromeDriver driver; + public ChromeDriver driver; public void openBrowser(){ driver =new ChromeDriver(); driver.manage().window().maximize(); - driver.get("https://mahara.org/?login"); + driver.get("https://www.saucedemo.com/"); } public void closeBrowser(){ driver.close(); diff --git a/src/test/java/pageobjectdesignpattern/CustomerListPage.java b/src/test/java/pageobjectdesignpattern/CustomerListPage.java index 8187ea0..def8819 100644 --- a/src/test/java/pageobjectdesignpattern/CustomerListPage.java +++ b/src/test/java/pageobjectdesignpattern/CustomerListPage.java @@ -1,5 +1,6 @@ package pageobjectdesignpattern; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.FindBy; @@ -13,19 +14,27 @@ public class CustomerListPage { ChromeDriver driver; FunctionsLibrary functionsLibrary; - @FindBy(linkText = "Add Customer") - WebElement addCustomerLink; - @FindBy(id = "cust-title") - WebElement titleField; - @FindBy(id = "name") + @FindBy(id = "react-burger-menu-btn") + WebElement dropLink; + @FindBy(id = "add-to-cart-sauce-labs-backpack") + WebElement addToCart; + @FindBy(id = "add-to-cart-sauce-labs-onesie") + WebElement addToCart1; + @FindBy(id = "shopping_cart_container") + WebElement shopingCar; + @FindBy(id = "checkout") + WebElement checkOut; + @FindBy(id = "first-name") WebElement firstNameField; - @FindBy(id = "name") + @FindBy(id = "last-name") WebElement lastNameField; - @FindBy(id = "name") - WebElement emailField; - @FindBy(name = "save") - WebElement saveButton; - @FindBy(id = "customer successfully added") + @FindBy(id = "postal-code") + WebElement zipCodeField; + @FindBy(id = "continue") + WebElement Continue; + @FindBy(id = "finish") + WebElement Finish; + @FindBy(className = "complete-header") WebElement customerAddedSuccessMessage; @@ -34,19 +43,29 @@ public CustomerListPage(ChromeDriver driver) { PageFactory.initElements(driver,this); functionsLibrary=new FunctionsLibrary(driver); } - public void addCustomer(String title,String firstName,String lastName,String email){ - functionsLibrary.waitForElementPresent(addCustomerLink); - addCustomerLink.click(); - functionsLibrary.waitForElementPresent(titleField); - titleField.sendKeys(title); + public void addCustomer(String zipCode,String firstName,String lastName,String email){ + functionsLibrary.waitForElementPresent(dropLink); + dropLink.click(); + functionsLibrary.waitForElementPresent(addToCart); + addToCart.click(); + functionsLibrary.waitForElementPresent(addToCart1); + addToCart.click(); + functionsLibrary.waitForElementPresent(shopingCar); + shopingCar.click(); + functionsLibrary.waitForElementPresent(checkOut); + checkOut.click(); functionsLibrary.waitForElementPresent(firstNameField); firstNameField.sendKeys(firstName); functionsLibrary.waitForElementPresent(lastNameField); lastNameField.sendKeys(lastName); - functionsLibrary.waitForElementPresent(emailField); - emailField.sendKeys(email); - functionsLibrary.waitForElementPresent(saveButton); - saveButton.click(); + functionsLibrary.waitForElementPresent(zipCodeField); + zipCodeField.sendKeys(zipCode); + functionsLibrary.waitForElementPresent(Continue); + Continue.click(); + functionsLibrary.waitForElementPresent(Finish); + Finish.click(); + + } public boolean verifyCustomerAdded(){ functionsLibrary.waitForElementPresent(customerAddedSuccessMessage); diff --git a/src/test/java/pageobjectdesignpattern/DashboardPage.java b/src/test/java/pageobjectdesignpattern/DashboardPage.java index f1379db..1a77260 100644 --- a/src/test/java/pageobjectdesignpattern/DashboardPage.java +++ b/src/test/java/pageobjectdesignpattern/DashboardPage.java @@ -13,21 +13,26 @@ public class DashboardPage { ChromeDriver driver; FunctionsLibrary functionsLibrary; -@FindBy(linkText = "Customer List") -WebElement customerListLink; -@FindBy(css="i.fa-sign-out") +@FindBy(id = "react-burger-menu-btn") +WebElement dropLink; +@FindBy(id = "logout_sidebar_link") WebElement logOutLink; public DashboardPage(ChromeDriver driver) { this.driver = driver; PageFactory.initElements(driver,this); functionsLibrary=new FunctionsLibrary(driver); } - public void clickCustomerListLink(){ - functionsLibrary.waitForElementPresent(customerListLink); - customerListLink.click(); + public void dropLink(){ + functionsLibrary.waitForElementPresent(dropLink); + dropLink.click(); + } + ////public void dropLink(){ + // functionsLibrary.waitForElementPresent(dropLink();dropLink.); + // } public void logOut(){ - functionsLibrary.waitForElementPresent(logOutLink);logOutLink.click(); + functionsLibrary.waitForElementPresent(logOutLink); + logOutLink.click(); } } diff --git a/src/test/java/pageobjectdesignpattern/LoginPage.java b/src/test/java/pageobjectdesignpattern/LoginPage.java index 30124d4..bffc764 100644 --- a/src/test/java/pageobjectdesignpattern/LoginPage.java +++ b/src/test/java/pageobjectdesignpattern/LoginPage.java @@ -14,17 +14,27 @@ public class LoginPage{ ChromeDriver driver; FunctionsLibrary functionsLibrary; - @FindBy(id = "login_login_username") + @FindBy(id = "user-name") WebElement userNameField; - @FindBy(id = "login_login_password") + @FindBy(id = "password") WebElement passwordField; - @FindBy(id = "login_submit") + @FindBy(id = "login-button") WebElement loginButton; public LoginPage(ChromeDriver driver) { this.driver = driver; + + + + + + + + + + PageFactory.initElements(driver,this); functionsLibrary=new FunctionsLibrary(driver); } From 5cfa6ccdfe814e39a3c7f93fbfee950b759f6677 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Mon, 18 Nov 2024 12:57:40 +0100 Subject: [PATCH 10/35] mahara login --- .../java/pageobjectdesignpattern/AddCustomerTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java index c0b67d6..aa5b9ae 100644 --- a/src/test/java/pageobjectdesignpattern/AddCustomerTest.java +++ b/src/test/java/pageobjectdesignpattern/AddCustomerTest.java @@ -41,9 +41,10 @@ public void addCustomerTest(){ dashboardPage.logOut(); } - // @AfterEach - //public void tearDown(){ - //closeBrowser(); - // } + @AfterEach + public void tearDown() + { + closeBrowser(); + } } From adac6cab24f49a8fa5e4eb49664f271bc3075e75 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Mon, 18 Nov 2024 13:11:42 +0100 Subject: [PATCH 11/35] TestNG Annotation and attributes. --- .idea/workspace.xml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e2ee401..b85ee24 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,14 +4,7 @@ - - - - - - - - + - + + + + + + + + - - - - - - - diff --git a/src/test/java/pageobjectdesignpattern/CustomerListPage1.java b/src/test/java/pageobjectdesignpattern/CustomerListPage1.java index 235e34b..3ee5b9b 100644 --- a/src/test/java/pageobjectdesignpattern/CustomerListPage1.java +++ b/src/test/java/pageobjectdesignpattern/CustomerListPage1.java @@ -36,8 +36,8 @@ public class CustomerListPage1 { WebElement saveProfile; @FindBy(id = "back-to-products") WebElement backToProducts; - @FindBy(className = "complete-header") - WebElement customerAddedSuccessMessage; + @FindBy(xpath = "//div[@class=\"alert alert-success\"]") + WebElement Success; public CustomerListPage1(ChromeDriver driver) { @@ -72,8 +72,8 @@ public void addCustomer(String zipCode,String firstName,String lastName,String e } public boolean verifyCustomerAdded(){ - functionsLibrary.waitForElementPresent(customerAddedSuccessMessage); - if (customerAddedSuccessMessage.isDisplayed()) + functionsLibrary.waitForElementPresent(Success); + if (Success.isDisplayed()) return true; else return false; diff --git a/src/test/java/pageobjectdesignpattern/mahara1.java b/src/test/java/pageobjectdesignpattern/mahara1.java index 569082a..1272196 100644 --- a/src/test/java/pageobjectdesignpattern/mahara1.java +++ b/src/test/java/pageobjectdesignpattern/mahara1.java @@ -21,8 +21,8 @@ public class mahara1 extends BaseClass1 { @BeforeClass public void setUp() { openBrowser(); - loginPage1 =new LoginPage1(driver); - dashboardPage1=new DashboardPage1(driver); + loginPage1 =new LoginPage1(driver); + dashboardPage1=new DashboardPage1(driver); functionsLibrary = new FunctionsLibrary(driver); customerListPage1 = new CustomerListPage1(driver); @@ -38,7 +38,7 @@ public void loginTest(String userName, String password) { } -@Test(priority = 2) + @Test(priority = 2) public void addCustomerTest(){ customerListPage1.addBlogAddress.click(); customerListPage1.addEmailAddress.click(); @@ -46,19 +46,19 @@ public void addCustomerTest(){ Faker faker=new Faker(); String firstName=faker.name().firstName(); String lastname=faker.name().lastName(); - String email=faker.internet().emailAddress(); + String email=faker.internet().emailAddress(); customerListPage1.officialWebsite.sendKeys(email); //customerListPage1.Country.click(); customerListPage1.Town.sendKeys(lastname); customerListPage1.mobileNumber.sendKeys(firstName); - customerListPage1.saveProfile.click(); + customerListPage1.saveProfile.submit(); //customerListPage.addCustomer("mr","ali","alim","asd@email.com"); - // Assertions.assertTrue(customerListPage1.verifyCustomerAdded()); - // dashboardPage.dropLink(); - // dashboardPage.logOut(); + + Assertions.assertTrue(customerListPage1.verifyCustomerAdded()); + } @@ -77,15 +77,16 @@ public Object[][] customerInfo() { return customerDetails; }*/ - /// @AfterClass - // public void tearDown(){ + @AfterClass + public void tearDown(){ - // dashboardPage1.dropLink(); - // dashboardPage1.logOut(); - // closeBrowser(); + dashboardPage1.dropLink(); + dashboardPage1.logOut(); + closeBrowser(); - // } + + } From 8441e5fe6d4f8ab590df348f8097e9f4f9e48925 Mon Sep 17 00:00:00 2001 From: ismetsasaq Date: Sun, 8 Dec 2024 12:41:43 +0100 Subject: [PATCH 19/35] TestNG Annotation and attributes. --- .idea/workspace.xml | 79 ++++++++--------- .../AdvanceActionsDemo.java | 68 +++++++++++++++ .../DashboardPage1.java | 17 ++-- .../EducationPage.java | 84 +++++++++++++++++++ .../FunctionsLibrary.java | 4 + .../testngframework/ScreenShotUtility.java | 35 ++++++++ .../java/testngframework/TestNGRunner.java | 33 +++++++- .../testngframework/TestResultListener.java | 17 ++++ 8 files changed, 291 insertions(+), 46 deletions(-) create mode 100644 src/test/java/advanceactionsdemo/AdvanceActionsDemo.java create mode 100644 src/test/java/pageobjectdesignpattern/EducationPage.java create mode 100644 src/test/java/testngframework/ScreenShotUtility.java create mode 100644 src/test/java/testngframework/TestResultListener.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d65247e..5ffc64f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,14 @@ + + + + - - - - - + + +