From 6935d87c4555612e5fcc6e4838781387edca2cfd Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 22 Dec 2024 22:08:45 +0530 Subject: [PATCH 01/14] Add files via upload --- Java/Activities/Activity1.java | 19 +++++++++++++ Java/Activities/Activity2.java | 44 ++++++++++++++++++++++++++++++ Java/Activities/Activity3.java | 31 +++++++++++++++++++++ Java/Activities/Activity4.java | 31 +++++++++++++++++++++ Java/Activities/Activity5.java | 50 ++++++++++++++++++++++++++++++++++ Java/Activities/Car.java | 32 ++++++++++++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 Java/Activities/Activity1.java create mode 100644 Java/Activities/Activity2.java create mode 100644 Java/Activities/Activity3.java create mode 100644 Java/Activities/Activity4.java create mode 100644 Java/Activities/Activity5.java create mode 100644 Java/Activities/Car.java diff --git a/Java/Activities/Activity1.java b/Java/Activities/Activity1.java new file mode 100644 index 0000000000..0dc773fd0e --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,19 @@ + + +package Activities; + +public class Activity1 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + Car carObj = new Car("Red", "Manual", 2020); + System.out.println(); + + carObj.displayCharactesristics(); + carObj.accelerate(); + carObj.brake(); + + } + +} \ No newline at end of file diff --git a/Java/Activities/Activity2.java b/Java/Activities/Activity2.java new file mode 100644 index 0000000000..126e50c05e --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,44 @@ + +package Activities; + +public class Activity2 { + + public static void main(String[] args) { + + Activity2 actObj = new Activity2(); + + int[] nums = {10, 77, 10, 54, -11, 10}; + + int searchNum = 10; + + int fixedSum = 10; + + System.out.println("Result: " + actObj.result(nums, searchNum, fixedSum)); + + } + + public boolean result(int[] nums, int searchNum, int fixedSum) + { + int tempSum = 0; + + for(int number: nums) + { + if(number == searchNum) { + tempSum += searchNum; + } + + if(tempSum > fixedSum) { + break; + } + } + + return fixedSum == tempSum; + } + +} + + + + + + diff --git a/Java/Activities/Activity3.java b/Java/Activities/Activity3.java new file mode 100644 index 0000000000..df05ed7e22 --- /dev/null +++ b/Java/Activities/Activity3.java @@ -0,0 +1,31 @@ + +package Activities; + +public class Activity3 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + double seconds = 1000000000; + + double EarthSeconds = 31557600; + double MercurySeconds = 0.2408467; + double VenusSeconds = 0.61519726; + double MarsSeconds = 1.8808158; + double JupiterSeconds = 11.862615; + double SaturnSeconds = 29.447498; + double UranusSeconds = 84.016846; + double NeptuneSeconds = 164.79132; + + System.out.println("Age on Mercury: " + seconds / EarthSeconds / MercurySeconds); + System.out.println("Age on Venus: " + seconds / EarthSeconds / VenusSeconds); + System.out.println("Age on Earth: " + seconds / EarthSeconds); + System.out.println("Age on Mars: " + seconds / EarthSeconds / MarsSeconds); + System.out.println("Age on Jupiter: " + seconds / EarthSeconds / JupiterSeconds); + System.out.println("Age on Saturn: " + seconds / EarthSeconds / SaturnSeconds); + System.out.println("Age on Uranus: " + seconds / EarthSeconds / UranusSeconds); + System.out.println("Age on Neptune: " + seconds / EarthSeconds / NeptuneSeconds); + } + + +} diff --git a/Java/Activities/Activity4.java b/Java/Activities/Activity4.java new file mode 100644 index 0000000000..d178682d8a --- /dev/null +++ b/Java/Activities/Activity4.java @@ -0,0 +1,31 @@ +package Activities; + +import java.util.Arrays; + +public class Activity4 { + + public static void main(String args[]) { + Activity4 actObj = new Activity4(); + int[] nums = { 10, 9, 47, 210, 24, 5, 26 }; + Activity4.insertionSort(nums); + System.out.println("Sorted Array: " + Arrays.toString(nums)); + } + + static void insertionSort(int[] nums) { + int size = nums.length; + + for (int i = 1; i < size; i++) { + int key = nums[i]; + int j = i - 1; + + while (j >= 0 && key < nums[j]) { + nums[j + 1] = nums[j]; + --j; + } + nums[j + 1] = key; + } + } + + + +} \ No newline at end of file diff --git a/Java/Activities/Activity5.java b/Java/Activities/Activity5.java new file mode 100644 index 0000000000..7213dd5203 --- /dev/null +++ b/Java/Activities/Activity5.java @@ -0,0 +1,50 @@ +package Activities; + +//Abstract class +abstract class Book { + + String title; + //Abstract method + public abstract void setTitle(String title); + + //Concrete method + public String getTitle() { + return this.title; + } +} + +class MyBook extends Book { + //Define abstract method + public void setTitle(String title) { + this.title = title; + } +} + +class MyBook2 extends Book { + //Define abstract method + public void setTitle(String title) { + if(title.length() > 3) + { + System.out.println("Title is too small"); + } + else + { + this.title = title; + } + } + } + +public class Activity5 { + + public static void main(String []args) { + //Initialize title of the book + String title = "Parcy Jakson and the Lightening Thief"; + //Create object for MyBook + Book bookObj = new MyBook(); + //Set title + bookObj.setTitle(title); + + //Print result + System.out.println("The title is: " + bookObj.getTitle()); + } +} \ No newline at end of file diff --git a/Java/Activities/Car.java b/Java/Activities/Car.java new file mode 100644 index 0000000000..c066dda105 --- /dev/null +++ b/Java/Activities/Car.java @@ -0,0 +1,32 @@ +package Activities; + +public class Car { + String color; +String transmission; +int make; +int tyres; +int doors; + +Car (String color,String transmisson,int make ){ + this.color = color; + this.transmission = transmission; + this.make = make; + this.tyres = 4; + this.doors = 4; +} +public void displayCharactesristics() { + System.out.println("color:" + color); + System.out.println("Transmission type:" + transmission); + System.out.println("Year of making :" + make); + System.out.println("No.of tyres:" + tyres); + System.out.println("No.of doors:" + doors); + +} +public void accelerate() { +System.out.println("car is moving forward"); +} +public void brake() { +System.out.println("car is stopped"); +} +} + From e0ad60d4c7179b21f513d105cd22009cf1d0001c Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 22 Dec 2024 22:35:03 +0530 Subject: [PATCH 02/14] Add files via upload --- Java/Activities/Activity6.java | 72 ++++++++++++++++++++++++++++++++ Java/Activities/Activity7.java | 75 ++++++++++++++++++++++++++++++++++ Java/Activities/Activity8.java | 50 +++++++++++++++++++++++ Java/Activities/Car.java | 71 ++++++++++++++++++++------------ 4 files changed, 241 insertions(+), 27 deletions(-) create mode 100644 Java/Activities/Activity6.java create mode 100644 Java/Activities/Activity7.java create mode 100644 Java/Activities/Activity8.java diff --git a/Java/Activities/Activity6.java b/Java/Activities/Activity6.java new file mode 100644 index 0000000000..dccf095680 --- /dev/null +++ b/Java/Activities/Activity6.java @@ -0,0 +1,72 @@ +package Activities; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +class Plane { + private List passengers; //List is Generic class, so used <> + private int maxPassengers; + private Date lastTakeOffTime; + private Date lastLandingTime; + + public Plane(int maxPassengers) { + this.maxPassengers = maxPassengers; + this.passengers = new ArrayList(); + } + + public void onboard(String passengerName) { + this.passengers.add(passengerName); + } + + public void settakeOff() { + this.lastTakeOffTime = new Date(); + } + + public Date getTakeOffTime() { + return this.lastTakeOffTime; + } + + public void setland() { + this.lastLandingTime = new Date(); + this.passengers.clear(); + } + + public Date getLastTimeLanded() { + return this.lastLandingTime; + } + + public List getPassengers() { + return this.passengers; + } +} + +public class Activity6 { + + public static void main(String[] args) throws InterruptedException { + + //There is a plane with max 10 passengers + Plane plane = new Plane(10); + + //Add passengers on the list + plane.onboard("Reddy"); + plane.onboard("Rao"); + plane.onboard("Choudary"); + + //Plane takes off time + plane.settakeOff(); + System.out.println("Plane took off at: " + plane.getTakeOffTime()); + + //Print list of people on board + System.out.println("People on the plane: " + plane.getPassengers()); + + //Flying..... + System.out.println("Plane is flying...."); + Thread.sleep(5000); + + //Plane has landed on time + plane.setland(); + System.out.println("Plane landed at: " + plane.getLastTimeLanded()); + System.out.println("The passengers on the plane after landing: " + plane.getPassengers()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity7.java b/Java/Activities/Activity7.java new file mode 100644 index 0000000000..5ffc038bfb --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,75 @@ +package Activities; + +interface BicycleParts { + public static final int tyres = 2; //by default is static and final + public int maxSpeed = 45; +} + +interface BicycleOperations { + public void applyBrake(int decrement); + public void speedUp(int increment); +} + +//Base class +class Bicycle implements BicycleParts, BicycleOperations { + + public int gears; + public int currentSpeed; + + //the Bicycle class has one constructor + public Bicycle(int gears, int currentSpeed) { + this.gears = gears; + this.currentSpeed = currentSpeed; + } + + //Bicycle class has three methods + public void applyBrake(int decrement) { + currentSpeed -= decrement; + System.out.println("Current speed: " + currentSpeed); + } + + public void speedUp(int increment) { + currentSpeed += increment; + System.out.println("Current speed: " + currentSpeed); + } + + //Method to print info of Bicycle + public String bicycleDesc() { + return("No of gears are "+ gears + "\nNo. of tyres are " + tyres); + } +} + +//Derived class +class MountainBike extends Bicycle { + + //The MountainBike subclass adds one more field + public int seatHeight; + + //The MountainBike subclass has one constructor + public MountainBike(int gears, int currentSpeed, int startHeight) { + //Invoking base-class(Bicycle) constructor + super(gears, currentSpeed); + seatHeight = startHeight; + } + + // the MountainBike subclass adds one more method + public void setHeight(int newValue) { + seatHeight = newValue; + } + + public String bicycleDesc() { + return (super.bicycleDesc()+ "\nSeat height is " + seatHeight); + } +} + +//Driver class +public class Activity7 { + public static void main(String args[]) { + MountainBike mb = new MountainBike(6, 0, 2); + System.out.println(mb.bicycleDesc()); + mb.speedUp(10); + System.out.println(mb.bicycleDesc()); + mb.applyBrake(5); + System.out.println(mb.bicycleDesc()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity8.java b/Java/Activities/Activity8.java new file mode 100644 index 0000000000..fd73dace28 --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,50 @@ +package Activities; + +class CustomException extends Exception +{ + private String message = null; + + public CustomException(String message) + { + this.message = message; + } + + @Override + + public String getMessage() + { + return message; + } + + } +public class Activity8 { + + public static void main(String[] args) { + + try { + + Activity8.exceptionTest("Will print to Console"); + + Activity8.exceptionTest(null); + + Activity8.exceptionTest("Won't execute"); + + } catch (CustomException ex) + { + System.out.println("Inside catch block: " + ex.getMessage()); + } + } + + static void exceptionTest(String str) throws CustomException + { + if(str==null) + { + throw new CustomException("String value is null"); + } + else + { + System.out.println(str); + } + } + +} \ No newline at end of file diff --git a/Java/Activities/Car.java b/Java/Activities/Car.java index c066dda105..302f888b08 100644 --- a/Java/Activities/Car.java +++ b/Java/Activities/Car.java @@ -1,32 +1,49 @@ + package Activities; public class Car { - String color; -String transmission; -int make; -int tyres; -int doors; - -Car (String color,String transmisson,int make ){ - this.color = color; - this.transmission = transmission; - this.make = make; - this.tyres = 4; - this.doors = 4; -} -public void displayCharactesristics() { - System.out.println("color:" + color); - System.out.println("Transmission type:" + transmission); - System.out.println("Year of making :" + make); - System.out.println("No.of tyres:" + tyres); - System.out.println("No.of doors:" + doors); + -} -public void accelerate() { -System.out.println("car is moving forward"); -} -public void brake() { -System.out.println("car is stopped"); -} -} + String color; + String transmission; + int make; + int tyres; + int doors; + Car(String color, String transmission, int make) + { + this.tyres = 4; + this.doors = 4; + this.color = color; + this.transmission = transmission; + this.make = make; + + } + + public void displayCharacteristics() + { + System.out.println("Color: " +color); + System.out.println("Tranmission type: " +transmission); + System.out.println("Years of making: " +make); + System.out.println("No. of tyres: " +tyres); + System.out.println("No. of doors: " +doors); + + } + + public void accelerate() + { + System.out.println("Car is moving forward"); + + } + + public void brake() + { + System.out.println("Car is stopped"); + } + + public void displayCharactesristics() { + // TODO Auto-generated method stub + + } + +} From 6745e25890d3d6adaaf261c21d8f00c710674074 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 17:49:15 +0530 Subject: [PATCH 03/14] Add files via upload --- Python/Activity1.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Python/Activity1.py diff --git a/Python/Activity1.py b/Python/Activity1.py new file mode 100644 index 0000000000..dca99dc1f6 --- /dev/null +++ b/Python/Activity1.py @@ -0,0 +1,4 @@ +name= input("Enter your name") +age = int(input("Enter your age:")) +result= name +",you will turn 89 in {}".format((2025-age)+100) +print(result) \ No newline at end of file From 4945742dbbed72d8302a827d4b8466d611ce7483 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 17:50:08 +0530 Subject: [PATCH 04/14] Delete Python/Activity1.py --- Python/Activity1.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 Python/Activity1.py diff --git a/Python/Activity1.py b/Python/Activity1.py deleted file mode 100644 index dca99dc1f6..0000000000 --- a/Python/Activity1.py +++ /dev/null @@ -1,4 +0,0 @@ -name= input("Enter your name") -age = int(input("Enter your age:")) -result= name +",you will turn 89 in {}".format((2025-age)+100) -print(result) \ No newline at end of file From ee19ff5bd9c631d7032e31783c45fdfa651dd3d0 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 17:50:33 +0530 Subject: [PATCH 05/14] Add files via upload --- Python/Activities/Activity1.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Python/Activities/Activity1.py diff --git a/Python/Activities/Activity1.py b/Python/Activities/Activity1.py new file mode 100644 index 0000000000..dca99dc1f6 --- /dev/null +++ b/Python/Activities/Activity1.py @@ -0,0 +1,4 @@ +name= input("Enter your name") +age = int(input("Enter your age:")) +result= name +",you will turn 89 in {}".format((2025-age)+100) +print(result) \ No newline at end of file From c8a47c94020432d0fdd2b3e83d507855e89dbf39 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 18:35:17 +0530 Subject: [PATCH 06/14] Add files via upload --- Appium/Activities/Activity1.java | 71 ++++++++++++++++++ Appium/Activities/Activity2.java | 76 ++++++++++++++++++++ Appium/Activities/Activity3.java | 119 +++++++++++++++++++++++++++++++ Appium/Activities/Activity4.java | 86 ++++++++++++++++++++++ Appium/Activities/Activity5.java | 91 +++++++++++++++++++++++ Appium/Activities/Activity6.java | 96 +++++++++++++++++++++++++ Appium/Activities/Activity7.java | 85 ++++++++++++++++++++++ Appium/Activities/Activity8.java | 27 +++++++ 8 files changed, 651 insertions(+) create mode 100644 Appium/Activities/Activity1.java create mode 100644 Appium/Activities/Activity2.java create mode 100644 Appium/Activities/Activity3.java create mode 100644 Appium/Activities/Activity4.java create mode 100644 Appium/Activities/Activity5.java create mode 100644 Appium/Activities/Activity6.java create mode 100644 Appium/Activities/Activity7.java create mode 100644 Appium/Activities/Activity8.java diff --git a/Appium/Activities/Activity1.java b/Appium/Activities/Activity1.java new file mode 100644 index 0000000000..12c173a022 --- /dev/null +++ b/Appium/Activities/Activity1.java @@ -0,0 +1,71 @@ +package Activity; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.xml.crypto.URIReferenceException; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity1Test { + + //Declare Appium driver + AppiumDriver driver ; + + //Setup function + @BeforeClass + public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.calculator"); + options.setAppActivity("com.android.calculator2.Calculator"); +// options.setApp("path/to/.apk"); + options.noReset(); + + + //Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + //Initialize the driver + driver = new AndroidDriver(serverURL, options); + } + //Test Function + @Test + public void multiplicationTest() { + //Find digit 5 and tap it + driver.findElement(AppiumBy.id("digit_5")).click(); + //Find plus symbol and tap it + driver.findElement(AppiumBy.accessibilityId("multiply")).click(); + //Find digit 2 and tap it + driver.findElement(AppiumBy.id("digit_2")).click(); + //Find equals symbol and tap it + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + //Assertions + String result = driver.findElement(AppiumBy.id("result_final")).getText(); + assertEquals(result,"10"); + } + + + //Tear down function + @AfterClass + public void tearDown() { + // Close the app + + driver.quit(); + } + +} \ No newline at end of file diff --git a/Appium/Activities/Activity2.java b/Appium/Activities/Activity2.java new file mode 100644 index 0000000000..f0ccadb023 --- /dev/null +++ b/Appium/Activities/Activity2.java @@ -0,0 +1,76 @@ +package Activity; + + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.xml.crypto.URIReferenceException; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity2 { + //Declare Appium driver + AppiumDriver driver ; + + //Setup function + @BeforeClass + public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); +// options.setApp("path/to/.apk"); + options.noReset(); + + + //Server URL + + URL serverURL = new URI("http://localhost:4723").toURL(); + + //Initialize the driver + driver = new AndroidDriver(serverURL, options); + + // Open the browser with the URL- https://training-support.net + driver.get("https://training-support.net"); + + + } + //Test Function + @Test + public void displayPageHeading() { + + // Locate heading on page and print it + String pageTitle = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text='Training Support']")).getText(); + System.out.println("Heading: " + pageTitle); + + // Find and click the About Us link + driver.findElement(AppiumBy.accessibilityId("About Us")).click(); + + // Find heading of new page and print to console + String aboutPageHeading = driver.findElement(AppiumBy.xpath( + "//android.widget.TextView[@text='About Us']" + )).getText(); + System.out.println(aboutPageHeading); + + + } + + //Tear down function + @AfterClass + public void tearDown() { + // Close the app + + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity3.java b/Appium/Activities/Activity3.java new file mode 100644 index 0000000000..613b71fc32 --- /dev/null +++ b/Appium/Activities/Activity3.java @@ -0,0 +1,119 @@ +package Activity; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.xml.crypto.URIReferenceException; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity3 { + //Declare Appium driver + AppiumDriver driver ; + + //Setup function + @BeforeClass + public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.calculator"); + options.setAppActivity("com.android.calculator2.Calculator"); +// options.setApp("path/to/.apk"); + options.noReset(); + + + //Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + //Initialize the driver + driver = new AndroidDriver(serverURL, options); + } + + //Test Function + @Test (priority=1) + public void additionTest() { + //Find digit 5 and tap it + driver.findElement(AppiumBy.id("digit_5")).click(); + //Find plus symbol and tap it + driver.findElement(AppiumBy.accessibilityId("plus")).click(); + //Find digit 9 and tap it + driver.findElement(AppiumBy.id("digit_9")).click(); + //Find equals symbol and tap it + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + //Assertions + String result = driver.findElement(AppiumBy.id("result_final")).getText(); + assertEquals(result,"14"); + } + //Test Function + @Test(priority=2) + public void subtractionTest() { + //Find digit 10 and tap it + driver.findElement(AppiumBy.id("digit_1")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + //Find plus symbol and tap it + driver.findElement(AppiumBy.accessibilityId("minus")).click(); + //Find digit 5 and tap it + driver.findElement(AppiumBy.id("digit_5")).click(); + //Find equals symbol and tap it + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + //Assertions + String result = driver.findElement(AppiumBy.id("result_final")).getText(); + assertEquals(result,"5"); + } + //Test Function + @Test(priority=3) + public void multiplicationTest() { + //Find digit 5 and tap it + driver.findElement(AppiumBy.id("digit_5")).click(); + //Find plus symbol and tap it + driver.findElement(AppiumBy.accessibilityId("multiply")).click(); + //Find digit 100 and tap it + driver.findElement(AppiumBy.id("digit_1")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + //Find equals symbol and tap it + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + //Assertions + String result = driver.findElement(AppiumBy.id("result_final")).getText(); + assertEquals(result,"500"); + } + //Test Function + @Test(priority=4) + public void divisionTest() { + //Find digit 50 and tap it + driver.findElement(AppiumBy.id("digit_5")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + //Find plus symbol and tap it + driver.findElement(AppiumBy.accessibilityId("divide")).click(); + //Find digit 2 and tap it + driver.findElement(AppiumBy.id("digit_2")).click(); + //Find equals symbol and tap it + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + //Assertions + String result = driver.findElement(AppiumBy.id("result_final")).getText(); + assertEquals(result,"25"); + } + + + //Tear down function + @AfterClass + public void tearDown() { + // Close the app + + driver.quit(); + } + + } \ No newline at end of file diff --git a/Appium/Activities/Activity4.java b/Appium/Activities/Activity4.java new file mode 100644 index 0000000000..0b773722b3 --- /dev/null +++ b/Appium/Activities/Activity4.java @@ -0,0 +1,86 @@ +package Activity; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import javax.xml.crypto.URIReferenceException; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity4 { + //Declare Appium driver + AppiumDriver driver ; + WebDriverWait wait; + + //Setup function + @BeforeClass + public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.contacts"); + options.setAppActivity("com.google.android.apps.contacts.quickcontact.QuickContactActivity"); +// options.setApp("path/to/.apk"); + options.noReset(); + + //Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + //Initialize the driver + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + //Test Function + @Test + public void addNewContact() { + //Find and click the button to add a new contact. + driver.findElement(AppiumBy.accessibilityId("Phone")).click(); + driver.findElement(AppiumBy.accessibilityId("Create new contact")).click(); + + + // Wait for elements to load + wait.until(ExpectedConditions.elementToBeClickable( + AppiumBy.xpath("//android.widget.EditText[@text='First name']") + )); + + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='First name']")).sendKeys("Aaditya"); + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='Last name']")).sendKeys("Varma"); + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text='Phone']")).sendKeys("999148292"); + driver.findElement(AppiumBy.id("com.google.android.contacts:id/toolbar_button")).click(); + + + //Assertions + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("large_title"))); + + // Assertion + String contactName = driver.findElement(AppiumBy.id("large_title")).getText(); + Assert.assertEquals(contactName, "Aaditya Varma"); + } + + + //Tear down function + @AfterClass + public void tearDown() { + // Close the app + + driver.quit(); + } + +} \ No newline at end of file diff --git a/Appium/Activities/Activity5.java b/Appium/Activities/Activity5.java new file mode 100644 index 0000000000..d482976e8d --- /dev/null +++ b/Appium/Activities/Activity5.java @@ -0,0 +1,91 @@ +package Activity; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import javax.xml.crypto.URIReferenceException; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.nativekey.AndroidKey; +import io.appium.java_client.android.nativekey.KeyEvent; +import io.appium.java_client.android.nativekey.PressesKey; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity5 { + //Declare Appium driver + AppiumDriver driver ; + WebDriverWait wait; + + //Setup function + @BeforeClass + public void setUp() throws MalformedURLException ,URIReferenceException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.apps.messaging"); + options.setAppActivity(".ui.ConversationListActivity"); +// options.setApp("path/to/.apk"); + options.noReset(); + + + //Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + + //Initialize the driver + driver = new AndroidDriver(serverURL, options); + } + //Test Function + @Test + public void sendSMS() { + driver.findElement(AppiumBy.accessibilityId("Start new conversation")).click(); + + // Wait for elements to load + wait.until(ExpectedConditions.elementToBeClickable( + AppiumBy.id("recipient_text_view") + )); + + // Find the element to add recipient + driver.findElement(AppiumBy.id("recipient_text_view")).sendKeys("18282832912"); + // Press ENTER + ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.ENTER)); + + // Wait for textbox to appear + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("compose_message_text"))); + + // Enter text to send + driver.findElement(AppiumBy.id("compose_message_text")).sendKeys("Hello from Appium"); + // Press Send + driver.findElement(AppiumBy.accessibilityId("Send SMS")).click(); + + // Assertion + String messageTextSent = driver.findElement(AppiumBy.id("message_text")).getText(); + Assert.assertEquals(messageTextSent, "Hello from Appium"); + + } + + + //Tear down function + @AfterClass + public void tearDown() { + // Close the app + + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity6.java b/Appium/Activities/Activity6.java new file mode 100644 index 0000000000..ef9eb4d82f --- /dev/null +++ b/Appium/Activities/Activity6.java @@ -0,0 +1,96 @@ +package Activity; + +import static Activity.ActionBase.doSwipe; +import static org.testng.Assert.assertTrue; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity6Test { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://training-support.net/webelements/sliders"); + } + + @Test + public void volume75Test() { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + // Get the size of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the start and end points + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .75)); + Point end = new Point((int) (dims.getWidth() * .67), (int) (dims.getHeight() * .75)); + // Perform swipe + doSwipe(driver, start, end, 2000); + + // Get the volume level + String volumeText = driver + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + .getText(); + + // Assertions + //assertTrue(volumeText.contains("75%")); + } + + @Test + public void volume25Test() { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + // Get the size of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the start and end points + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .75)); + Point end = new Point((int) (dims.getWidth() * .34), (int) (dims.getHeight() * .75)); + // Perform swipe + doSwipe(driver, start, end, 2000); + + // Get the volume level + String volumeText = driver + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + .getText(); + + // Assertions + //assertTrue(volumeText.contains("25%")); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity7.java b/Appium/Activities/Activity7.java new file mode 100644 index 0000000000..5b56197e66 --- /dev/null +++ b/Appium/Activities/Activity7.java @@ -0,0 +1,85 @@ +package Activity; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity7 { + // Driver Declaration + AndroidDriver driver; + WebDriverWait wait; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page in Chrome + driver.get("https://training-support.net/webelements/lazy-loading"); + } + + // Test method + @Test + public void uiScrollableTest() { + // Wait for page to load + wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.className("android.widget.Image"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Find all the image elements on the page + List imageElements = driver.findElements(AppiumBy.className("android.widget.Image")); + // Print the number of images + System.out.println("Before scroll: " + imageElements.size()); + + // Scroll to required element + String imageText = driver.findElement(AppiumBy + .androidUIAutomator(UiScrollable + ".scrollForward(25).getChildByText(className(\"android.widget.Image\"), \"Helen\")")) + .getText(); + System.out.println("Found " + imageText + "!"); + + // Get image elements after scroll + imageElements = driver.findElements(AppiumBy.className("android.widget.Image")); + // Print the number of images after scroll + System.out.println("After scroll: " + imageElements.size()); + + // Assertions + Assert.assertEquals(imageElements.size(), 3); + } + + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } + + +} \ No newline at end of file diff --git a/Appium/Activities/Activity8.java b/Appium/Activities/Activity8.java new file mode 100644 index 0000000000..0e043cbe61 --- /dev/null +++ b/Appium/Activities/Activity8.java @@ -0,0 +1,27 @@ +package Activity; + + +import org.openqa.selenium.Point; +import org.openqa.selenium.interactions.PointerInput; +import org.openqa.selenium.interactions.Sequence; + +import static java.time.Duration.ofMillis; +import static org.openqa.selenium.interactions.PointerInput.MouseButton.LEFT; +import static org.openqa.selenium.interactions.PointerInput.Origin.viewport; + +import java.util.Arrays; + +import io.appium.java_client.AppiumDriver; + +public class ActionBase { + private final static PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); + + public static void doSwipe(AppiumDriver driver, Point start, Point end, int duration) { + Sequence swipe = new Sequence(finger, 1) + .addAction(finger.createPointerMove(ofMillis(0), viewport(), start.getX(), start.getY())) + .addAction(finger.createPointerDown(LEFT.asArg())) + .addAction(finger.createPointerMove(ofMillis(duration), viewport(), end.getX(), end.getY())) + .addAction(finger.createPointerUp(LEFT.asArg())); + driver.perform(Arrays.asList(swipe)); + } +} \ No newline at end of file From 4cd01bb5184ec92f5a91b9d10488f18880b8452e Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 18:43:24 +0530 Subject: [PATCH 07/14] Add files via upload --- Appium/Project/Activity1Login.java | 110 ++++++++++++++++++++++++ Appium/Project/Activity2popup.java | 101 ++++++++++++++++++++++ Appium/Project/Activity3Todolist.java | 103 ++++++++++++++++++++++ Appium/Project/Activity4KeepNotes.java | 72 ++++++++++++++++ Appium/Project/Activity5KeepNotes.java | 80 +++++++++++++++++ Appium/Project/Activity6GoogleTask.java | 81 +++++++++++++++++ 6 files changed, 547 insertions(+) create mode 100644 Appium/Project/Activity1Login.java create mode 100644 Appium/Project/Activity2popup.java create mode 100644 Appium/Project/Activity3Todolist.java create mode 100644 Appium/Project/Activity4KeepNotes.java create mode 100644 Appium/Project/Activity5KeepNotes.java create mode 100644 Appium/Project/Activity6GoogleTask.java diff --git a/Appium/Project/Activity1Login.java b/Appium/Project/Activity1Login.java new file mode 100644 index 0000000000..226d778a73 --- /dev/null +++ b/Appium/Project/Activity1Login.java @@ -0,0 +1,110 @@ +package LiveProject; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity1Login { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://v1.training-support.net/selenium"); + } + + @Test(priority = 1) + public void loginTestwithCorrectCreds() throws InterruptedException { + // Wait for page to load + wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Selenium']"))); + // driver.manage().window().getSize(); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Scroll to required element + Thread.sleep(5000); + driver.findElement(AppiumBy.androidUIAutomator(UiScrollable + + ".scrollForward(2).getChildByText(className(\"android.widget.TextView\"), \"Login Form\")")); + + // Wait for page to load + wait.until(ExpectedConditions + .elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Login Form']"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath( + "//android.webkit.WebView[@text='Login Form']/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText[1]"))) + .sendKeys("admin"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath( + "//android.webkit.WebView[@text='Login Form']/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText[2]"))) + .sendKeys("password"); + driver.findElement(AppiumBy.xpath("//android.widget.Button[@text=\"Log in\"]")).click(); + + // Assertions + String LoginMsg = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Welcome Back, admin\"]")) + .getText(); + Assert.assertTrue(LoginMsg.contains("Welcome Back")); + } + + @Test(priority = 2) + public void loginTestwithWrongCreds() throws InterruptedException { + // Wait for page to load + wait.until( + ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Selenium']"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Scroll to required element + Thread.sleep(5000); + driver.findElement(AppiumBy.androidUIAutomator(UiScrollable + + ".scrollForward(4).getChildByText(className(\"android.widget.TextView\"), \"Login Form\")")); + + // Wait for page to load + wait.until(ExpectedConditions + .elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Login Form']"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath( + "//android.webkit.WebView[@text='Login Form']/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText[1]"))) + .sendKeys("admin"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath( + "//android.webkit.WebView[@text='Login Form']/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText[2]"))) + .sendKeys("password"); + driver.findElement(AppiumBy.xpath("//android.widget.Button[@text=\"Log in\"]")).click(); + + // Assertions + String LoginMsg = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Invalid Credentials\"]")) + .getText(); + Assert.assertTrue(LoginMsg.contains("Invalid")); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Project/Activity2popup.java b/Appium/Project/Activity2popup.java new file mode 100644 index 0000000000..1502e5e898 --- /dev/null +++ b/Appium/Project/Activity2popup.java @@ -0,0 +1,101 @@ +package LiveProject; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity2popup { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://v1.training-support.net/selenium"); + + } + + @Test(priority=1) + public void loginOnPopUps() throws InterruptedException { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Selenium']"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Scroll to required element + driver.findElement(AppiumBy + .androidUIAutomator(UiScrollable + ".scrollForward(4).getChildByText(className(\"android.view.View\"), \"Popups\")")); + //Thread.sleep(10000); + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Popups\"]")).click(); + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text='Sign In']"))).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.xpath("//android.webkit.WebView[@text=\"Popups\"]/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.widget.EditText[1]")).sendKeys("admin"); + driver.findElement(AppiumBy.xpath("//android.webkit.WebView[@text=\"Popups\"]/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.widget.EditText[2]")).sendKeys("password"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text=\"Log in\"]"))).click(); + + // Assertions + String LoginMsg = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Welcome Back, admin\"]")) + .getText(); + Assert.assertTrue(LoginMsg.contains("Welcome Back")); + } + + @Test(priority=2) + public void loginFailOnPopUps() throws InterruptedException { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Selenium']"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Scroll to required element + driver.findElement(AppiumBy + .androidUIAutomator(UiScrollable + ".scrollForward(4).getChildByText(className(\"android.view.View\"), \"Popups\")")); + //Thread.sleep(10000); + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Popups\"]")).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text='Sign In']"))).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.xpath("//android.webkit.WebView[@text=\"Popups\"]/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.widget.EditText[1]")).sendKeys("admin"); + driver.findElement(AppiumBy.xpath("//android.webkit.WebView[@text=\"Popups\"]/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.widget.EditText[2]")).sendKeys("pass"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text=\"Log in\"]"))).click(); + + // Assertions + String LoginMsg = driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Invalid Credentials\"]")) + .getText(); + Assert.assertTrue(LoginMsg.contains("Invalid")); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } + + + +} \ No newline at end of file diff --git a/Appium/Project/Activity3Todolist.java b/Appium/Project/Activity3Todolist.java new file mode 100644 index 0000000000..4200688438 --- /dev/null +++ b/Appium/Project/Activity3Todolist.java @@ -0,0 +1,103 @@ +package LiveProject; + + + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity3ToDoList { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://v1.training-support.net/selenium"); + } + + @Test(priority=1) + public void toDoList() throws InterruptedException { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[@text='Selenium']"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Scroll to required element + driver.findElement(AppiumBy + .androidUIAutomator(UiScrollable + ".scrollForward(4).getChildByText(className(\"android.view.View\"), \"To-Do List\")")); + //Thread.sleep(10000); + driver.findElement(AppiumBy.xpath(" \r\n" + + "//android.widget.TextView[@text='To-Do List']")).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.webkit.WebView[@text=\"Todo List\"]/android.view.View/android.view.View/android.view.View[1]/android.widget.EditText"))); + WebElement taskInputBox = driver.findElement(AppiumBy.xpath("//android.webkit.WebView[@text=\"Todo List\"]/android.view.View/android.view.View/android.view.View[1]/android.widget.EditText")); + WebElement addTaskBtn = driver.findElement(AppiumBy.xpath("//android.widget.Button[@text=\"Add Task\"]")); + + //Add the below 3 tasks + taskInputBox.sendKeys("Add tasks to list"); + addTaskBtn.click(); + taskInputBox.sendKeys("Get number of tasks"); + addTaskBtn.click(); + taskInputBox.sendKeys("Clear the list"); + addTaskBtn.click(); + + //Click on the tasks to strike them out + List tasksList = driver.findElements(AppiumBy.xpath("//android.webkit.WebView[@text=\"Todo List\"]/android.view.View/android.view.View/android.view.View[2]/android.view.View")); + // System.out.println("size of list is : " +(tasksList.size()-1)); + for (int i = 0; i < tasksList.size(); i++) { + WebElement task = tasksList.get(i); + task.click(); +// Thread.sleep(10000); + } + + + //clear the list. + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\" Clear List\"]")).click(); + Thread.sleep(10000); + + + List tasksListNew = driver.findElements(AppiumBy.xpath("//android.webkit.WebView[@text=\"Todo List\"]/android.view.View/android.view.View")); + //Check if the number of tasks is zero +// System.out.println("size of new list is : " +(tasksListNew.size()-1)); + Assert.assertEquals((tasksListNew.size()-1), 0); + } + + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } + + +} \ No newline at end of file diff --git a/Appium/Project/Activity4KeepNotes.java b/Appium/Project/Activity4KeepNotes.java new file mode 100644 index 0000000000..9281d87813 --- /dev/null +++ b/Appium/Project/Activity4KeepNotes.java @@ -0,0 +1,72 @@ +package LiveProject; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity4KeepNotes { + // Driver Declaration + AndroidDriver driver; + WebDriverWait wait; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.keep"); + options.setAppActivity(".activities.BrowseActivity"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + } + + @Test + public void googleKeepTest() throws InterruptedException { + driver.findElement(AppiumBy.id("com.google.android.keep:id/speed_dial_create_close_button")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/new_note_button")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/editable_title")).sendKeys("Note1"); + driver.findElement(AppiumBy.id("com.google.android.keep:id/edit_note_text")).sendKeys("This is a test Note"); + + //Return back + driver.findElement(AppiumBy.accessibilityId("Navigate up")).click(); + String actuaNote = driver.findElement(AppiumBy.id("com.google.android.keep:id/index_note_title")).getText(); + Assert.assertTrue(actuaNote.contains("Note1")); + + //Remove the added note to make it work for the next time + driver.findElement(AppiumBy.id("com.google.android.keep:id/index_note_title")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/editor_action_button")).click(); + Thread.sleep(5000); + driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Delete\")")).click(); + Thread.sleep(2000); + } + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Project/Activity5KeepNotes.java b/Appium/Project/Activity5KeepNotes.java new file mode 100644 index 0000000000..dc5ae2ea50 --- /dev/null +++ b/Appium/Project/Activity5KeepNotes.java @@ -0,0 +1,80 @@ +package LiveProject; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity5KeepNotesReminder { + // Driver Declaration + AndroidDriver driver; + WebDriverWait wait; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.keep"); + options.setAppActivity(".activities.BrowseActivity"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + } + + @Test + public void googleKeepTest() throws InterruptedException { + driver.findElement(AppiumBy.id("com.google.android.keep:id/speed_dial_create_close_button")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/new_note_button")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/editable_title")).sendKeys("Note1"); + driver.findElement(AppiumBy.id("com.google.android.keep:id/edit_note_text")).sendKeys("This is a test Note"); + + //Add reminder + driver.findElement(AppiumBy.id("com.google.android.keep:id/menu_reminder")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Pick a date & time\")")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/save")).click(); + + //Return back + Thread.sleep(2000); + driver.findElement(AppiumBy.accessibilityId("Navigate up")).click(); + String actuaNote = driver.findElement(AppiumBy.id("com.google.android.keep:id/index_note_title")).getText(); + Assert.assertTrue(actuaNote.contains("Note1")); + + //Remove the added note to make it work for the next time + driver.findElement(AppiumBy.id("com.google.android.keep:id/index_note_title")).click(); + Thread.sleep(2000); + driver.findElement(AppiumBy.id("com.google.android.keep:id/editor_action_button")).click(); + Thread.sleep(5000); + driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"Delete\")")).click(); + Thread.sleep(2000); + } + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Project/Activity6GoogleTask.java b/Appium/Project/Activity6GoogleTask.java new file mode 100644 index 0000000000..8416677653 --- /dev/null +++ b/Appium/Project/Activity6GoogleTask.java @@ -0,0 +1,81 @@ +package LiveProject; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity6GoogleTasks { + // Driver Declaration + AndroidDriver driver; + WebDriverWait wait; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.google.android.apps.tasks"); + options.setAppActivity(".ui.TaskListsActivity"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + } + + @Test + public void googleTasksTest() throws InterruptedException { + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/tasks_fab")).click(); + Thread.sleep(1000); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_title")).sendKeys("Complete Activity with Google Tasks"); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_done")).click(); + Thread.sleep(1000); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/tasks_fab")).click(); + Thread.sleep(1000); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_title")).sendKeys("Complete Activity with Google Keep"); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_done")).click(); + Thread.sleep(1000); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/tasks_fab")).click(); + Thread.sleep(1000); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_title")).sendKeys("Complete the second Activity Google Keep"); + driver.findElement(AppiumBy.id("com.google.android.apps.tasks:id/add_task_done")).click(); + Thread.sleep(1000); + + List tasksList = driver.findElements(AppiumBy.xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.google.android.apps.tasks:id/tasks_list']/android.widget.FrameLayout")); +// System.out.println("Size of the Task list is:" +tasksList.size()); + Assert.assertEquals(tasksList.size(), 3); + + //Reset the task list to 0 + int task = 0; + while (task < tasksList.size()) { + driver.findElement(AppiumBy.xpath("//android.view.View[@content-desc='Mark as complete']")).click(); + task++; + } + } + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} \ No newline at end of file From 32df5f3445772fac4af158cb2085111a16d632a6 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 18:59:41 +0530 Subject: [PATCH 08/14] Create Feature --- Cucumber/Activities/Feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 Cucumber/Activities/Feature diff --git a/Cucumber/Activities/Feature b/Cucumber/Activities/Feature new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Cucumber/Activities/Feature @@ -0,0 +1 @@ + From 708ca99d2140788db6d3364ae7c78cbad30f7fb6 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 18:59:56 +0530 Subject: [PATCH 09/14] Delete Cucumber/Activities/Feature --- Cucumber/Activities/Feature | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Cucumber/Activities/Feature diff --git a/Cucumber/Activities/Feature b/Cucumber/Activities/Feature deleted file mode 100644 index 8b13789179..0000000000 --- a/Cucumber/Activities/Feature +++ /dev/null @@ -1 +0,0 @@ - From 50e912224abae6dca8ba93f0e4a68c38c36320c6 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 19:29:31 +0530 Subject: [PATCH 10/14] Add files via upload --- Cucumber/Activity.feature | 8 +++++++ Cucumber/Activity1.feature | 6 ++++++ Cucumber/Activity2.feature | 8 +++++++ Cucumber/Activity3.feature | 44 ++++++++++++++++++++++++++++++++++++++ Cucumber/Activity5.feature | 12 +++++++++++ Cucumber/Activity6.feature | 29 +++++++++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 Cucumber/Activity.feature create mode 100644 Cucumber/Activity1.feature create mode 100644 Cucumber/Activity2.feature create mode 100644 Cucumber/Activity3.feature create mode 100644 Cucumber/Activity5.feature create mode 100644 Cucumber/Activity6.feature diff --git a/Cucumber/Activity.feature b/Cucumber/Activity.feature new file mode 100644 index 0000000000..2629ca5dfd --- /dev/null +++ b/Cucumber/Activity.feature @@ -0,0 +1,8 @@ +@activity4 +Feature: Data driven test without Examples + + Scenario: Testing with correct data from inputs + Given the user is on the login page + When the user enters "admin" and "password" + And clicks the submit button + Then get the confirmation text and verify message as "Welcome Back, admin" \ No newline at end of file diff --git a/Cucumber/Activity1.feature b/Cucumber/Activity1.feature new file mode 100644 index 0000000000..1c3b13898b --- /dev/null +++ b/Cucumber/Activity1.feature @@ -0,0 +1,6 @@ +@activity1 +Feature: First Test + Scenario: Opening a webpage using Selenium + Given User is on Google Home Page + When User types in Cheese and hits ENTER + Then Show how many search results were shown \ No newline at end of file diff --git a/Cucumber/Activity2.feature b/Cucumber/Activity2.feature new file mode 100644 index 0000000000..205e391c6b --- /dev/null +++ b/Cucumber/Activity2.feature @@ -0,0 +1,8 @@ +@activity2 +Feature: Activity to test the login feature + + Scenario: Successful login + Given the user is on the login page + When the user enters username and password + And clicks the submit button + Then get the confirmation message and verify it \ No newline at end of file diff --git a/Cucumber/Activity3.feature b/Cucumber/Activity3.feature new file mode 100644 index 0000000000..4a4a440730 --- /dev/null +++ b/Cucumber/Activity3.feature @@ -0,0 +1,44 @@ +@activity3 +Feature: Testing with Tags + + @SimpleAlert @SmokeTest + Scenario: Test for Simple Alert + Given User is on the page + When User clicks the Simple Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert + And Read the result text + + @ConfirmAlert + Scenario: Test for Confirm Alert + Given User is on the page + When User clicks the Confirmation Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert with Cancel + And Read the result text + + @PromptAlert + Scenario: Test for Prompt Alert + Given User is on the page + When User clicks the Prompt Alert button + Then Alert opens + And Read the text from it and print it + And Write a custom message in it + And Close the alert + And Read the result text + + # An alternate approach using Scenario outline + Scenario Outline: + Given User is on the page + When User clicks the Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert + And Read the result text + Examples: + | Type | + | Simple | + | Confirmation | + | Prompt | \ No newline at end of file diff --git a/Cucumber/Activity5.feature b/Cucumber/Activity5.feature new file mode 100644 index 0000000000..053d313e88 --- /dev/null +++ b/Cucumber/Activity5.feature @@ -0,0 +1,12 @@ +@activity5 +Feature: Data driven test with Examples + + Scenario Outline: Testing with Data from Scenario + Given the user is on the login page + When the user enters "" and "" + And clicks the submit button + Then get the confirmation text and verify message as "" + + Examples: + | Usernames | Passwords | Message | + | admin | password | Welcome Back, Admin! | \ No newline at end of file diff --git a/Cucumber/Activity6.feature b/Cucumber/Activity6.feature new file mode 100644 index 0000000000..af69ab77ca --- /dev/null +++ b/Cucumber/Activity6.feature @@ -0,0 +1,29 @@ +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +Feature: Data driven test with DataTable + +@DataTable +Scenario: Testing the To-Do app + Given User completes the requirement + When User enters the following tasks + | task1 | + | task2 | + | task3 | + Then Verify results \ No newline at end of file From 2e355c29716ad860f6a4440300a35253a1d2841b Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 19:46:56 +0530 Subject: [PATCH 11/14] Features --- Cucumber/Features | 1 + 1 file changed, 1 insertion(+) create mode 100644 Cucumber/Features diff --git a/Cucumber/Features b/Cucumber/Features new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Cucumber/Features @@ -0,0 +1 @@ + From 0aacc2f4fbd8c00df86ceba39badf77d1c3d5567 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 19:48:51 +0530 Subject: [PATCH 12/14] StepDefinations --- Cucumber/AlertTestSteps.java | 66 ++++++++++++++++++++++++++++++++ Cucumber/DataTableSteps.java | 34 +++++++++++++++++ Cucumber/Fixtures.java | 25 ++++++++++++ Cucumber/GoogleSearchSteps.java | 28 ++++++++++++++ Cucumber/LoginTestSteps.java | 68 +++++++++++++++++++++++++++++++++ Cucumber/baseclass.java | 10 +++++ 6 files changed, 231 insertions(+) create mode 100644 Cucumber/AlertTestSteps.java create mode 100644 Cucumber/DataTableSteps.java create mode 100644 Cucumber/Fixtures.java create mode 100644 Cucumber/GoogleSearchSteps.java create mode 100644 Cucumber/LoginTestSteps.java create mode 100644 Cucumber/baseclass.java diff --git a/Cucumber/AlertTestSteps.java b/Cucumber/AlertTestSteps.java new file mode 100644 index 0000000000..46fc3452ce --- /dev/null +++ b/Cucumber/AlertTestSteps.java @@ -0,0 +1,66 @@ +package stepDefinitions; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class AlertTestSteps extends BaseClass { + Alert alert; + + @Given("User is on the page") + public void openPage() { + // Open browser + driver.get("https://training-support.net/webelements/alerts"); + } + + @When("User clicks the Simple Alert button") + public void openSimpleAlert() { + driver.findElement(By.id("simple")).click(); + } + + @When("User clicks the Confirmation Alert button") + public void openConfirmAlert() { + driver.findElement(By.id("confirmation")).click(); + } + + @When("User clicks the Prompt Alert button") + public void openPromptAlert() { + driver.findElement(By.id("prompt")).click(); + } + + @Then("Alert opens") + public void switchFocus() { + alert = driver.switchTo().alert(); + } + + @And("Read the text from it and print it") + public void readAlert() { + System.out.println("Alert says: " + alert.getText()); + } + + @And("Write a custom message in it") + public void writeToPrompt() { + alert.sendKeys("Custom Message"); + } + + @And("Close the alert") + public void closeAlert() { + alert.accept(); + } + + @And("Close the alert with Cancel") + public void closeAlertWithCAncel() { + alert.dismiss(); + } + + @And("Read the result text") + public void readResultText() { + String message = driver.findElement(By.id("result")).getText(); + System.out.println("Action performed: " + message); + } + +} \ No newline at end of file diff --git a/Cucumber/DataTableSteps.java b/Cucumber/DataTableSteps.java new file mode 100644 index 0000000000..27983ec12a --- /dev/null +++ b/Cucumber/DataTableSteps.java @@ -0,0 +1,34 @@ +package stepDefinitions; + +import java.util.List; +import io.cucumber.datatable.DataTable; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.openqa.selenium.By; + +public class DataTableSteps extends BaseClass { + @Given("User completes the requirement") + public void completeRequirement() { + driver.get("https://training-support.net/webelements/todo-list"); + System.out.println("Given completed"); + } + + @When("User enters the following tasks") + public void inputTasks(DataTable inputTasks) throws InterruptedException { + List tasks = inputTasks.asList(); + System.out.println(tasks); + + for(String task : tasks) { + driver.findElement(By.id("todo-input")).sendKeys(task); + driver.findElement(By.id("todo-add")).click(); + Thread.sleep(2000); + } + } + + @Then("Verify results") + public void verifyResults() { + System.out.println("Verification complete"); + } + +} \ No newline at end of file diff --git a/Cucumber/Fixtures.java b/Cucumber/Fixtures.java new file mode 100644 index 0000000000..ca94ca3960 --- /dev/null +++ b/Cucumber/Fixtures.java @@ -0,0 +1,25 @@ +package stepDefinitions; + +import java.time.Duration; + + +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.cucumber.java.AfterAll; +import io.cucumber.java.BeforeAll; + +public class Fixtures extends BaseClass { + @BeforeAll + public static void setUp() { + //Initialize Firefox Driver + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(60)); + } + + @AfterAll + public static void tearDown() { + //close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Cucumber/GoogleSearchSteps.java b/Cucumber/GoogleSearchSteps.java new file mode 100644 index 0000000000..f83a5c849c --- /dev/null +++ b/Cucumber/GoogleSearchSteps.java @@ -0,0 +1,28 @@ +package stepDefinitions; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class GoogleSearchSteps extends BaseClass { + @Given("User is on the Google homepage") + public void userIsOnGooglePage() throws Throwable { + //Open the browser + driver.get("https://www.google.com"); + } + @When("User types in Cheese and hits ENTER") + public void userTypesInCheeseAndHitsENTER() throws Throwable { + driver.findElement(By.name("q")).sendKeys("Cheese", Keys.ENTER); + } + @Then("Show how many search results were shown") + public void showHowManySearchResultsWereShown() throws Throwable { + wait.until(ExpectedConditions.elementToBeClickable(By.id("hdtb-tls"))).click(); + String resultStats = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("result-stats"))).getText(); + System.out.println("Number of results found: " + resultStats); + + } +} \ No newline at end of file diff --git a/Cucumber/LoginTestSteps.java b/Cucumber/LoginTestSteps.java new file mode 100644 index 0000000000..c684ee1e78 --- /dev/null +++ b/Cucumber/LoginTestSteps.java @@ -0,0 +1,68 @@ +package stepDefinitions; + +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class LoginTestSteps extends BaseClass { + + @Given("the user is on the login page") + public void openPage() throws Throwable { + // Open the login page + driver.get("https://training-support.net/webelements/login-form"); + // Assert page title + Assertions.assertEquals("Selenium: Login Form", driver.getTitle()); + } + + @When("the user enters username and password") + public void enterCredentials() throws Throwable { + // Find username field and enter username + driver.findElement(By.id("username")).sendKeys("admin"); + // Find password field and enter password + driver.findElement(By.id("password")).sendKeys("password"); + } + + @When("the user enters {string} and {string}") + public void enterCredentialsFromInputs(String username, String password) throws Throwable { + // Find the input fields + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + // Clear the fields + usernameField.clear(); + passwordField.clear(); + // Find username field and enter username + usernameField.sendKeys(username); + // Find password field and enter password + passwordField.sendKeys(password); + } + + @And("clicks the submit button") + public void clickSubmit() throws Throwable { + // Find the submit button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + } + + @Then("get the confirmation message and verify it") + public void confirmMessage() throws Throwable { + // Find the confirmation message + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h2.mt-5"), "Welcome")); + String message = driver.findElement(By.cssSelector("h2.mt-5")).getText(); + // Assert message + Assertions.assertEquals("Welcome Back, Admin!", message); + } + + @Then("get the confirmation text and verify message as {string}") + public void confirmMessageAsInput(String expectedMessage) throws Throwable { + // Find the confirmation message + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h2.mt-5"), "Welcome")); + String message = driver.findElement(By.cssSelector("h2.mt-5")).getText(); + // Assert message + Assertions.assertEquals(expectedMessage, message); + } +} diff --git a/Cucumber/baseclass.java b/Cucumber/baseclass.java new file mode 100644 index 0000000000..4e76d40dbd --- /dev/null +++ b/Cucumber/baseclass.java @@ -0,0 +1,10 @@ +package stepDefinitions; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BaseClass { + //create a new instance of the firefox driver. + static WebDriver driver; + static WebDriverWait wait; +} \ No newline at end of file From ba31f03e586f2a997cfe35b7b4cd2334a70df817 Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 19:50:27 +0530 Subject: [PATCH 13/14] Rename .gitkeep to Features --- Cucumber/Activities/.gitkeep | 0 Cucumber/Activities/Features | 1 + 2 files changed, 1 insertion(+) delete mode 100644 Cucumber/Activities/.gitkeep create mode 100644 Cucumber/Activities/Features diff --git a/Cucumber/Activities/.gitkeep b/Cucumber/Activities/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Cucumber/Activities/Features b/Cucumber/Activities/Features new file mode 100644 index 0000000000..d3f5a12faa --- /dev/null +++ b/Cucumber/Activities/Features @@ -0,0 +1 @@ + From 6e63aa5cd55f0136de93f3229ad7a9a3a02222ee Mon Sep 17 00:00:00 2001 From: vamsinagella Date: Sun, 23 Feb 2025 19:51:04 +0530 Subject: [PATCH 14/14] Delete Cucumber/Activities/Features --- Cucumber/Activities/Features | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Cucumber/Activities/Features diff --git a/Cucumber/Activities/Features b/Cucumber/Activities/Features deleted file mode 100644 index d3f5a12faa..0000000000 --- a/Cucumber/Activities/Features +++ /dev/null @@ -1 +0,0 @@ -