From 471f98588abe9dacb05a884eba746f00b309a266 Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Fri, 27 Dec 2024 19:40:50 +0530 Subject: [PATCH 1/6] Added Java Activity files --- Java/Activities/Activity1.java | 11 +++++ Java/Activities/Activity10.java | 36 +++++++++++++++ Java/Activities/Activity11.java | 37 +++++++++++++++ Java/Activities/Activity12.java | 22 +++++++++ Java/Activities/Activity13.java | 31 +++++++++++++ Java/Activities/Activity14.java | 41 +++++++++++++++++ Java/Activities/Activity2.java | 39 ++++++++++++++++ Java/Activities/Activity3.java | 6 +++ Java/Activities/Activity4.java | 34 ++++++++++++++ Java/Activities/Activity5.java | 37 +++++++++++++++ Java/Activities/Activity6.java | 62 ++++++++++++++++++++++++++ Java/Activities/Activity7.java | 79 +++++++++++++++++++++++++++++++++ Java/Activities/Activity9.java | 30 +++++++++++++ Java/Activities/Car.java | 36 +++++++++++++++ 14 files changed, 501 insertions(+) create mode 100644 Java/Activities/Activity1.java create mode 100644 Java/Activities/Activity10.java create mode 100644 Java/Activities/Activity11.java create mode 100644 Java/Activities/Activity12.java create mode 100644 Java/Activities/Activity13.java create mode 100644 Java/Activities/Activity14.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/Activity6.java create mode 100644 Java/Activities/Activity7.java create mode 100644 Java/Activities/Activity9.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..50085863b4 --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,11 @@ +package activities; + +public class Activity1 { + + public static void main(String[] args) { + Car carobj=new Car("Red","Manual",2024); + carobj.displayCharacteristics(); + carobj.accelarate(); + carobj.brake(); + } +} diff --git a/Java/Activities/Activity10.java b/Java/Activities/Activity10.java new file mode 100644 index 0000000000..5e004e7226 --- /dev/null +++ b/Java/Activities/Activity10.java @@ -0,0 +1,36 @@ +package activities; + +import java.util.HashSet; +import java.util.Set; + +public class Activity10 { + public static void main(String[] args) { + Set hs = new HashSet(); + // Adding element to HashSet + hs.add("M"); + hs.add("B"); + hs.add("C"); + hs.add("A"); + hs.add("M"); + hs.add("X"); + + //Print HashSet + System.out.println("Original HashSet: " + hs); + //Print size of HashSet + System.out.println("Size of HashSet: " + hs.size()); + + //Remove element + System.out.println("Removing A from HashSet: " + hs.remove("A")); + //Remove element that is not present + if(hs.remove("Z")) { + System.out.println("Z removed from the Set"); + } else { + System.out.println("Z is not present in the Set"); + } + + //Search for element + System.out.println("Checking if M is present: " + hs.contains("M")); + //Print updated HashSet + System.out.println("Updated HashSet: " + hs); + } +} diff --git a/Java/Activities/Activity11.java b/Java/Activities/Activity11.java new file mode 100644 index 0000000000..38836cff8c --- /dev/null +++ b/Java/Activities/Activity11.java @@ -0,0 +1,37 @@ +package activities; + +import java.util.HashMap; + +public class Activity11 { + + public static void main(String[] args) { + HashMap hashmap = new HashMap(); + hashmap.put(1, "Red"); + hashmap.put(2, "Green"); + hashmap.put(3, "Blue"); + hashmap.put(4, "White"); + hashmap.put(5, "Black"); + + // Print the Map + System.out.println("The Original map: " + hashmap); + + // Remove one colour + hashmap.remove(4); + // Map after removing a colour + System.out.println("After removing White: " + hashmap); + + // Check if green exists + if(hashmap.containsValue("Green")) { + System.out.println("Green exists in the Map"); + } else { + System.out.println("Green does not exist in the Map"); + } + + // Print the size of the Map + System.out.println("Number of pairs in the Map is: " + hashmap.size()); + //loop through Map + for(int key:hashmap.keySet()) { + System.out.println(hashmap.get(key)); + } + } +} diff --git a/Java/Activities/Activity12.java b/Java/Activities/Activity12.java new file mode 100644 index 0000000000..c62400f0eb --- /dev/null +++ b/Java/Activities/Activity12.java @@ -0,0 +1,22 @@ +package activities; + +@FunctionalInterface +interface Addable { + int add(int a, int b); +} +public class Activity12 { + + public static void main(String[] args) { + + // Lambda expression without return keyword. + Addable ad1 = (a, b) -> (a + b); + System.out.println(ad1.add(10, 20)); + + // Lambda expression with return keyword. + Addable ad2 = (int a, int b) -> { + return (a + b); + }; + System.out.println(ad2.add(100, 200)); + } + +} diff --git a/Java/Activities/Activity13.java b/Java/Activities/Activity13.java new file mode 100644 index 0000000000..c95ae2c321 --- /dev/null +++ b/Java/Activities/Activity13.java @@ -0,0 +1,31 @@ +package activities; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Scanner; + +public class Activity13 { + public static void main(String[] args) { + //Create the Objects + Scanner scan = new Scanner(System.in); + List list = new ArrayList<>(); + Random indexGen = new Random(); + //statements to show users to indicate when they can type + System.out.print("Enter integers for the list "); + System.out.println("Enter a EOF or non-integer to terminate): "); + //Loop to take only integers from console + while(scan.hasNextInt()) { + list.add(scan.nextInt()); + } + + Integer nums[] = list.toArray(new Integer[0]); + //Generate random Index + int index = indexGen.nextInt(nums.length); + System.out.println("Random Index value generated: " + index); + System.out.println("Value in arary at generated index: " + nums[index]); + + scan.close(); + } + +} diff --git a/Java/Activities/Activity14.java b/Java/Activities/Activity14.java new file mode 100644 index 0000000000..dcea5d290f --- /dev/null +++ b/Java/Activities/Activity14.java @@ -0,0 +1,41 @@ +package activities; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; + +public class Activity14 { + + public static void main(String[] args) throws IOException { + try { + File file = new File("src/session4/newfile.txt"); + boolean fStatus = file.createNewFile(); + if(fStatus) { + System.out.println("File created successfully!"); + } else { + System.out.println("File already exists at this path."); + } + + //get the file Object + File fileUtil = FileUtils.getFile("src/session4/newfile.txt"); + //Read file + System.out.println("Data in file: " + FileUtils.readFileToString(fileUtil, "UTF8")); + + //Create directory + File destDir = new File("resources"); + //Copy file to directory + FileUtils.copyFileToDirectory(file, destDir); + + //Get file from new directory + File newFile = FileUtils.getFile(destDir, "newfile.txt"); + //Read data from file + String newFileData = FileUtils.readFileToString(newFile, "UTF8"); + //Print it + System.out.println("Data in new file: " + newFileData); + } catch(IOException errMessage) { + System.out.println(errMessage); + } + } + +} diff --git a/Java/Activities/Activity2.java b/Java/Activities/Activity2.java new file mode 100644 index 0000000000..2a97c20cd9 --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,39 @@ +package activities; + +public class Activity2 { + + public static void main(String[] args) { + // creates the object for the class to call the functions exist in this class + Activity2 actobj=new Activity2(); + int[] numarray= {10, 77, 10, 54, -11, 10}; + //set the numbers to serach for + int searchNum=10; + + int fixedsum=30; + + //call the result function and print the result + System.out.println("Result :"+actobj.result(numarray,searchNum,fixedsum)); + } + + public boolean result(int[] numarray, int searchNum, int fixedsum) { + // TODO Auto-generated method stub + int tempsum =0; + for(int number:numarray) { + //check if the number is search Num + if(number == searchNum) { + //Add the Value + tempsum=tempsum+searchNum; + + //tempsum +=searchNum; + } + + //check if tempsum is greater than fixedNum + if(tempsum > fixedsum) { + //condition fails, break loop + break; + } + } + return fixedsum == tempsum; + } + +} diff --git a/Java/Activities/Activity3.java b/Java/Activities/Activity3.java new file mode 100644 index 0000000000..e773f35bf1 --- /dev/null +++ b/Java/Activities/Activity3.java @@ -0,0 +1,6 @@ +package activities; + +public class Activity3 { + + +} diff --git a/Java/Activities/Activity4.java b/Java/Activities/Activity4.java new file mode 100644 index 0000000000..bc574126d7 --- /dev/null +++ b/Java/Activities/Activity4.java @@ -0,0 +1,34 @@ +package activities; + +import java.util.Arrays; + +public class Activity4 { + + public static void main(String args[]) { + Activity4 actobj=new Activity4(); + int[] data = { 9, 5, 1, 4, 3 }; + //call the function to sort the array + actobj.ascendingSort(data); + System.out.println("Sorted Array in Ascending Order: "); + System.out.println(Arrays.toString(data)); + } + + public void ascendingSort(int[] data) { + //set the size of the array + int size = data.length; + //loop through the array + //Starting from second value + for (int i = 1; i < size; i++) { + //Set the Key value and the first compare value + int key = data[i]; + int j = i - 1; + //Check if Key is lesser + //If it is, + while (j >= 0 && key < data[j]) { + data[j + 1] = data[j]; + --j; + } + data[j + 1] = key; + } + } +} diff --git a/Java/Activities/Activity5.java b/Java/Activities/Activity5.java new file mode 100644 index 0000000000..b192913b20 --- /dev/null +++ b/Java/Activities/Activity5.java @@ -0,0 +1,37 @@ +package activities; + + public class Activity5 { + + public static void main(String []args) { + //Initialize title of the book + String title = "Hover Car Racer"; + //Create object for MyBook + Book newNovel = new MyBook(); + //Set title + newNovel.setTitle(title); + + //Print result + System.out.println("The title is: " + newNovel.getTitle()); + } + } + + //Abstract class + abstract class Book { + String title; + //Abstract method + abstract void setTitle(String s); + + //Concrete method + String getTitle() { + return title; + } + } + + class MyBook extends Book { + //Define abstract method + public void setTitle(String s) { + title = s; + } + } + + diff --git a/Java/Activities/Activity6.java b/Java/Activities/Activity6.java new file mode 100644 index 0000000000..cb2b69e3b7 --- /dev/null +++ b/Java/Activities/Activity6.java @@ -0,0 +1,62 @@ +package activities; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +class Plane { + private List passengers; + private int maxPassengers; + private Date lastTimeTookOf; + private Date lastTimeLanded; + + public Plane(int maxPassengers) { + this.maxPassengers = maxPassengers; + this.passengers = new ArrayList<>(); + } + + public void onboard(String passenger) { + this.passengers.add(passenger); + } + + public Date takeOff() { + this.lastTimeTookOf = new Date(); + return lastTimeTookOf; + } + + public void land() { + this.lastTimeLanded = new Date(); + this.passengers.clear(); + } + + public Date getLastTimeLanded() { + return lastTimeLanded; + } + + public List getPassengers() { + return 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("John"); + plane.onboard("Steve"); + plane.onboard("Anna"); + //Plane takes off + System.out.println("Plane took off at: " + plane.takeOff()); + //Print list of people on board + System.out.println("People on the plane: " + plane.getPassengers()); + //Flying..... + Thread.sleep(5000); + //Plane has landed + plane.land(); + //Plane lands + System.out.println("Plane landed at: " + plane.getLastTimeLanded()); + System.out.println("People on the plane after landing: " + plane.getPassengers()); + } +} diff --git a/Java/Activities/Activity7.java b/Java/Activities/Activity7.java new file mode 100644 index 0000000000..8beede8c86 --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,79 @@ +package activities; + +interface BicycleParts { + /* + * public int gears = 0; public int currentSpeed = 0; + */ + + public int tyres=2; + public int maxspeed = 25; +} + +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 + "\nSpeed of bicycle is " + currentSpeed); + + 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(3, 0, 25); + System.out.println(mb.bicycleDesc()); + mb.speedUp(20); + mb.applyBrake(5); + } +} diff --git a/Java/Activities/Activity9.java b/Java/Activities/Activity9.java new file mode 100644 index 0000000000..af5a996524 --- /dev/null +++ b/Java/Activities/Activity9.java @@ -0,0 +1,30 @@ +package activities; + +import java.util.ArrayList; + +public class Activity9 { + public static void main(String[] args) { + //declaring Arraylist of String objects + ArrayList myList = new ArrayList(); + //Adding objects to Array List at default index + myList.add("Apple"); + myList.add("Mango"); + myList.add("Orange"); + //Adding object at specific index + myList.add(3, "Grapes"); + myList.add(1, "Papaya"); + + System.out.println("Print All the Objects:"); + for(String s:myList){ + System.out.println(s); + } + + System.out.println("3rd element in the list is: " + myList.get(2)); + System.out.println("Is Chicku is in list: " + myList.contains("Chicku")); + System.out.println("Size of ArrayList: " + myList.size()); + + myList.remove("Papaya"); + + System.out.println("New Size of ArrayList: " + myList.size()); + } +} diff --git a/Java/Activities/Car.java b/Java/Activities/Car.java new file mode 100644 index 0000000000..fc783ae5fb --- /dev/null +++ b/Java/Activities/Car.java @@ -0,0 +1,36 @@ +package activities; + +public class Car { + + String color; + String transmission; + int make; + int tyres; + int doors; + + Car(String color,String transmission,int make) { + this.color=color; + this.transmission=transmission; + this.make=make; + this.tyres=4; + this.doors=4; + } + + public void displayCharacteristics() { + System.out.println("Color :"+color); + System.out.println("Transmission Type :"+transmission); + System.out.println("yearof Making :"+make); + System.out.println("No.of Tyres :"+tyres); + System.out.println("No.of Doors :"+doors); + + } + + public void accelarate() { + System.out.println("Car is moving forward"); + } + + public void brake() { + System.out.println("Car has stopped"); + } + +} From db6ccffc8b24cc295028be9fa374e41f282ed407 Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:36:29 +0530 Subject: [PATCH 2/6] Added Activity8 to Java --- Java/Activities/Activity8.java | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Java/Activities/Activity8.java diff --git a/Java/Activities/Activity8.java b/Java/Activities/Activity8.java new file mode 100644 index 0000000000..02ab1886c0 --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,46 @@ +package activities; + +class CustomException extends Exception { + private String message= null; + + public CustomException(String message) { + this.message=message; + + } + public String getMessage(){ + return message; + } + +} + +public class Activity8 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + try { + //Method call with Correct input + Activity8.exceptionTest("Will print to control"); + //Method call with incorrect input + Activity8.exceptionTest(null); + + Activity8.exceptionTest("Won't execute"); + }catch(CustomException ex) { + + ex.printStackTrace(); + + System.out.println("Inside catch block:" +ex.getMessage()); + } + } + + static void exceptionTest(String str)throws CustomException { + // TODO Auto-generated method stub + if(str == null) { + throw new CustomException("String Value is null"); + } + else { + System.out.println(str); + } + } + +} From 22b3714512ddd4ca52718c0f6d6edb447c115469 Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:51:12 +0530 Subject: [PATCH 3/6] added junit activities --- JUnit/Activities/Activity1.java | 51 +++++++++++++++++++++++++++++++++ JUnit/Activities/Activity2.java | 32 +++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 JUnit/Activities/Activity1.java create mode 100644 JUnit/Activities/Activity2.java diff --git a/JUnit/Activities/Activity1.java b/JUnit/Activities/Activity1.java new file mode 100644 index 0000000000..9e2c08aefd --- /dev/null +++ b/JUnit/Activities/Activity1.java @@ -0,0 +1,51 @@ +package activities; + +import java.util.ArrayList; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Activity1 { + + // Test fixtures + static ArrayList list; + + // Initialize test fixtures before each test method + @BeforeEach + void setUp() throws Exception { + list = new ArrayList(); + list.add("alpha"); // at index 0 + list.add("beta"); // at index 1 + } + + // Test method to test the insert operation + @Test + public void insertTest() { + //Expected List + //List expectedList=Arrays.asList("alpha","beta","gama"); + // Assertion for size + assertEquals(2, list.size(), "Wrong size"); + // Add new element + list.add(2, "gama"); + // Assert with new elements + assertEquals(3, list.size(), "Wrong size"); + + // Assert individual elements + assertEquals("alpha", list.get(0), "Wrong element"); + assertEquals("beta", list.get(1), "Wrong element"); + assertEquals("gama", list.get(2), "Wrong element"); + } + + // Test method to test the replace operation + + @Test public void replaceTest() { + // Replace new element + list.set(1, "gama"); + + // Assert size of list + assertEquals(2, list.size(), "Wrong size"); + // Assert individual elements + assertEquals("alpha", list.get(0), "Wrong element"); + assertEquals("gama", list.get(1), "Wrong element"); } + +} diff --git a/JUnit/Activities/Activity2.java b/JUnit/Activities/Activity2.java new file mode 100644 index 0000000000..237e7cce24 --- /dev/null +++ b/JUnit/Activities/Activity2.java @@ -0,0 +1,32 @@ +package activities; + +import org.junit.jupiter.api.Test; +import activities.BankAccount; +import activities.NotEnoughFundsException; +import static org.junit.jupiter.api.Assertions.*; + +class ExpectedExceptionTest { + + @Test + void notEnoughFunds() { + // Create an object for BankAccount class + BankAccount account = new BankAccount(20); + + // Assertion for exception + assertThrows(NotEnoughFundsException.class, () -> account.withdraw(30), + "Balance must be greater than amount of withdrawal"); + } + + @Test + void enoughFunds() { + // Create an object for BankAccount class + BankAccount account = new BankAccount(100); + + //Expected balance + int expectedBalance=0; + + // Assertion for no exceptions + assertDoesNotThrow(() -> account.withdraw(10)); + assertEquals(expectedBalance, account.withdraw(90)); + } +} \ No newline at end of file From ad0836b80d919f1c341e26b26aa670d7bbb34dc4 Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Tue, 18 Feb 2025 07:42:43 +0530 Subject: [PATCH 4/6] Added selenium --- JUnit/Activities/CalculatorTest.java | 72 ++++++++++++++++++ Java/examples/Calculator.java | 11 +++ Java/examples/Hello.java | 11 +++ Selenium/Activities/Activity1.java | 28 +++++++ Selenium/Activities/Activity1.py | 17 +++++ Selenium/Activities/Activity10.java | 43 +++++++++++ Selenium/Activities/Activity10.py | 30 ++++++++ Selenium/Activities/Activity11.java | 44 +++++++++++ Selenium/Activities/Activity11.py | 31 ++++++++ Selenium/Activities/Activity12.java | 31 ++++++++ Selenium/Activities/Activity12.py | 21 ++++++ Selenium/Activities/Activity13.java | 40 ++++++++++ Selenium/Activities/Activity13.py | 27 +++++++ Selenium/Activities/Activity14.java | 40 ++++++++++ Selenium/Activities/Activity14.py | 31 ++++++++ Selenium/Activities/Activity15.java | 44 +++++++++++ Selenium/Activities/Activity15.py | 30 ++++++++ Selenium/Activities/Activity16.java | 50 +++++++++++++ Selenium/Activities/Activity16.py | 37 ++++++++++ Selenium/Activities/Activity17.java | 52 +++++++++++++ Selenium/Activities/Activity17.py | 36 +++++++++ Selenium/Activities/Activity18.java | 37 ++++++++++ Selenium/Activities/Activity18.py | 30 ++++++++ Selenium/Activities/Activity19.java | 40 ++++++++++ Selenium/Activities/Activity19.py | 29 ++++++++ Selenium/Activities/Activity2.java | 32 ++++++++ Selenium/Activities/Activity2.py | 29 ++++++++ Selenium/Activities/Activity20.java | 39 ++++++++++ Selenium/Activities/Activity20.py | 32 ++++++++ Selenium/Activities/Activity21.java | 56 ++++++++++++++ Selenium/Activities/Activity21.py | 40 ++++++++++ Selenium/Activities/Activity22.java | 44 +++++++++++ Selenium/Activities/Activity22.py | 32 ++++++++ Selenium/Activities/Activity3.java | 32 ++++++++ Selenium/Activities/Activity3.py | 29 ++++++++ Selenium/Activities/Activity4.java | 36 +++++++++ Selenium/Activities/Activity4.py | 29 ++++++++ Selenium/Activities/Activity5.java | 30 ++++++++ Selenium/Activities/Activity5.py | 23 ++++++ Selenium/Activities/Activity6.java | 31 ++++++++ Selenium/Activities/Activity6.py | 23 ++++++ Selenium/Activities/Activity7.java | 34 +++++++++ Selenium/Activities/Activity7.py | 20 +++++ Selenium/Activities/Activity8.java | 45 ++++++++++++ Selenium/Activities/Activity8.py | 34 +++++++++ Selenium/Activities/Activity9.java | 31 ++++++++ Selenium/Activities/Activity9.py | 21 ++++++ Selenium/Project/CRM_Activity1.java | 36 +++++++++ Selenium/Project/CRM_Activity1.py | 20 +++++ Selenium/Project/CRM_Activity2.java | 50 +++++++++++++ Selenium/Project/CRM_Activity2.py | 19 +++++ Selenium/Project/CRM_Activity3.java | 35 +++++++++ Selenium/Project/CRM_Activity3.py | 20 +++++ Selenium/Project/CRM_Activity4.java | 42 +++++++++++ Selenium/Project/CRM_Activity4.py | 25 +++++++ Selenium/Project/CRM_Activity5.java | 53 ++++++++++++++ Selenium/Project/CRM_Activity5.py | 32 ++++++++ Selenium/Project/CRM_Activity6.java | 60 +++++++++++++++ Selenium/Project/CRM_Activity6.py | 32 ++++++++ Selenium/Project/CRM_Activity7.java | 60 +++++++++++++++ Selenium/Project/CRM_Activity7.py | 41 +++++++++++ Selenium/Project/CRM_Activity8.java | 86 ++++++++++++++++++++++ Selenium/Project/CRM_Activity8.py | 46 ++++++++++++ Selenium/Project/CRM_Activity9.java | 105 +++++++++++++++++++++++++++ Selenium/Project/CRM_Activity9.py | 36 +++++++++ 65 files changed, 2382 insertions(+) create mode 100644 JUnit/Activities/CalculatorTest.java create mode 100644 Java/examples/Calculator.java create mode 100644 Java/examples/Hello.java create mode 100644 Selenium/Activities/Activity1.java create mode 100644 Selenium/Activities/Activity1.py create mode 100644 Selenium/Activities/Activity10.java create mode 100644 Selenium/Activities/Activity10.py create mode 100644 Selenium/Activities/Activity11.java create mode 100644 Selenium/Activities/Activity11.py create mode 100644 Selenium/Activities/Activity12.java create mode 100644 Selenium/Activities/Activity12.py create mode 100644 Selenium/Activities/Activity13.java create mode 100644 Selenium/Activities/Activity13.py create mode 100644 Selenium/Activities/Activity14.java create mode 100644 Selenium/Activities/Activity14.py create mode 100644 Selenium/Activities/Activity15.java create mode 100644 Selenium/Activities/Activity15.py create mode 100644 Selenium/Activities/Activity16.java create mode 100644 Selenium/Activities/Activity16.py create mode 100644 Selenium/Activities/Activity17.java create mode 100644 Selenium/Activities/Activity17.py create mode 100644 Selenium/Activities/Activity18.java create mode 100644 Selenium/Activities/Activity18.py create mode 100644 Selenium/Activities/Activity19.java create mode 100644 Selenium/Activities/Activity19.py create mode 100644 Selenium/Activities/Activity2.java create mode 100644 Selenium/Activities/Activity2.py create mode 100644 Selenium/Activities/Activity20.java create mode 100644 Selenium/Activities/Activity20.py create mode 100644 Selenium/Activities/Activity21.java create mode 100644 Selenium/Activities/Activity21.py create mode 100644 Selenium/Activities/Activity22.java create mode 100644 Selenium/Activities/Activity22.py create mode 100644 Selenium/Activities/Activity3.java create mode 100644 Selenium/Activities/Activity3.py create mode 100644 Selenium/Activities/Activity4.java create mode 100644 Selenium/Activities/Activity4.py create mode 100644 Selenium/Activities/Activity5.java create mode 100644 Selenium/Activities/Activity5.py create mode 100644 Selenium/Activities/Activity6.java create mode 100644 Selenium/Activities/Activity6.py create mode 100644 Selenium/Activities/Activity7.java create mode 100644 Selenium/Activities/Activity7.py create mode 100644 Selenium/Activities/Activity8.java create mode 100644 Selenium/Activities/Activity8.py create mode 100644 Selenium/Activities/Activity9.java create mode 100644 Selenium/Activities/Activity9.py create mode 100644 Selenium/Project/CRM_Activity1.java create mode 100644 Selenium/Project/CRM_Activity1.py create mode 100644 Selenium/Project/CRM_Activity2.java create mode 100644 Selenium/Project/CRM_Activity2.py create mode 100644 Selenium/Project/CRM_Activity3.java create mode 100644 Selenium/Project/CRM_Activity3.py create mode 100644 Selenium/Project/CRM_Activity4.java create mode 100644 Selenium/Project/CRM_Activity4.py create mode 100644 Selenium/Project/CRM_Activity5.java create mode 100644 Selenium/Project/CRM_Activity5.py create mode 100644 Selenium/Project/CRM_Activity6.java create mode 100644 Selenium/Project/CRM_Activity6.py create mode 100644 Selenium/Project/CRM_Activity7.java create mode 100644 Selenium/Project/CRM_Activity7.py create mode 100644 Selenium/Project/CRM_Activity8.java create mode 100644 Selenium/Project/CRM_Activity8.py create mode 100644 Selenium/Project/CRM_Activity9.java create mode 100644 Selenium/Project/CRM_Activity9.py diff --git a/JUnit/Activities/CalculatorTest.java b/JUnit/Activities/CalculatorTest.java new file mode 100644 index 0000000000..28cd2f6851 --- /dev/null +++ b/JUnit/Activities/CalculatorTest.java @@ -0,0 +1,72 @@ +package examples; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.aggregator.ArgumentsAccessor; +import org.junit.jupiter.params.provider.CsvFileSource; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; + + + +public class CalculatorTest { + + Calculator cal=new Calculator(); + + @Test + public void addTest(){ + + //Perform the add function to get the ACTUAl Val + int result1=cal.add(10,20); + int result2=cal.add(15,15); + int result3=cal.add(25,5); + //Perform the Assertion function to verify the result Val + //assertEquals(30,result); + //Add a assertion statement to verify against EXPECTED result + assertAll( + ()->assertEquals(30,result1), + ()->assertEquals(30,result2), + ()->assertEquals(30,result3) + ); + } + @Test + public void multiplyTest(){ + //Perform the multiply function to get the ACTUAl Val + int result1=cal.multiply(10,3); + //Perform the Assertion function to verify the result Val + assertEquals(30,result1); + } + + @ParameterizedTest + @ValueSource(ints= {10,20,25,100}) + public void paramSqrTest(int num) { + //perform the add function to get the ACTUAL result + int result=cal.square(num); + + //Add a assertion statement to verify against EXPECTED result + assertEquals(num*num , result); + } + + @ParameterizedTest + @CsvSource({ + "10,90", + "20, 80", + "50, 50" + }) + public void paramAddTest(int num1 , int num2) { + int result4= cal.add(num1, num2); + assertEquals(100, result4); + + } + + @ParameterizedTest + @CsvFileSource(files= "src/test/resources/input.csv", nullValues = {"N/A", "N/A", "-"}) + public void AggregateTest(ArgumentsAccessor args) { + System.out.println(args.getString(0) + "has only" + (args.getInteger(3)+3) + "sick days remaining"); + } + + +} diff --git a/Java/examples/Calculator.java b/Java/examples/Calculator.java new file mode 100644 index 0000000000..28096af2e9 --- /dev/null +++ b/Java/examples/Calculator.java @@ -0,0 +1,11 @@ +package examples; + +public class Calculator { + public int multiply(int a, int b) { + return a * b; + } + + public int add(int a, int b) { + return a + b; + } + } diff --git a/Java/examples/Hello.java b/Java/examples/Hello.java new file mode 100644 index 0000000000..f87eb8a283 --- /dev/null +++ b/Java/examples/Hello.java @@ -0,0 +1,11 @@ +package examples; + +public class Hello { + + public static void main(String[] args) { + // TODO Auto-generated method stub + System.out.println("Hello World!"); + + } + +} diff --git a/Selenium/Activities/Activity1.java b/Selenium/Activities/Activity1.java new file mode 100644 index 0000000000..22e591cdf6 --- /dev/null +++ b/Selenium/Activities/Activity1.java @@ -0,0 +1,28 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +import dev.failsafe.internal.util.Assert; + +public class Activity1 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net"); + + // Verify the page title + System.out.println("Page title is: " + driver.getTitle()); + // Find the About Us link and click it + driver.findElement(By.linkText("About Us")).click(); + // Print the page title of the About Us page + System.out.println("New page title is: " + driver.getTitle()); + + // Close the browser + driver.quit(); + } + } diff --git a/Selenium/Activities/Activity1.py b/Selenium/Activities/Activity1.py new file mode 100644 index 0000000000..cdcb7fea9e --- /dev/null +++ b/Selenium/Activities/Activity1.py @@ -0,0 +1,17 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the "About Us" button on the page using ID and click it + driver.find_element(By.LINK_TEXT, "About Us").click() + + # Print the title of the new page + print("New page title is: ", driver.title) \ No newline at end of file diff --git a/Selenium/Activities/Activity10.java b/Selenium/Activities/Activity10.java new file mode 100644 index 0000000000..12b210fa5d --- /dev/null +++ b/Selenium/Activities/Activity10.java @@ -0,0 +1,43 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity10 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + // Create the Actions object + Actions builder = new Actions(driver); + + // Open the page + driver.get("https://training-support.net/webelements/drag-drop"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the football + WebElement football = driver.findElement(By.id("ball")); + // Find the dropzone1 + WebElement dropzone1 = driver.findElement(By.id("dropzone1")); + // Find the dropzone2 + WebElement dropzone2 = driver.findElement(By.id("dropzone2")); + + // Perform drag and drop to dropzone 1 + builder.clickAndHold(football).moveToElement(dropzone1).pause(5000).release().build().perform(); + if(dropzone1.findElement(By.className("dropzone-text")).getText().equals("Dropped!")) { + System.out.println("Ball was dropped in Dropzone 1"); + } + + // Perform drag and drop to dropzone 2 + builder.dragAndDrop(football, dropzone2).pause(5000).build().perform(); + if(dropzone2.findElement(By.className("dropzone-text")).getText().equals("Dropped!")) { + System.out.println("Ball was dropped in Dropzone 2"); + } + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity10.py b/Selenium/Activities/Activity10.py new file mode 100644 index 0000000000..da44c75cec --- /dev/null +++ b/Selenium/Activities/Activity10.py @@ -0,0 +1,30 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/drag-drop") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the football + football = driver.find_element(By.ID, "ball") + # Find the dropzone1 + dropzone1 = driver.find_element(By.ID, "dropzone1") + # Find the dropzone2 + dropzone2 = driver.find_element(By.ID, "dropzone2") + + # Perform drag and drop to dropzone 1 + actions.click_and_hold(football).move_to_element(dropzone1).pause(5).release().perform() + if(dropzone1.find_element(By.CLASS_NAME, "dropzone-text").text == "Dropped!"): + print("Ball was dropped in Dropzone 1") + + # Perform drag and drop to dropzone 2 + actions.drag_and_drop(football, dropzone2).pause(5).perform() + if(dropzone2.find_element(By.CLASS_NAME, "dropzone-text").text == "Dropped!"): + print("Ball was dropped in Dropzone 2") \ No newline at end of file diff --git a/Selenium/Activities/Activity11.java b/Selenium/Activities/Activity11.java new file mode 100644 index 0000000000..f1852a777f --- /dev/null +++ b/Selenium/Activities/Activity11.java @@ -0,0 +1,44 @@ +package activities; +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity11 { + public static void main(String[] args) { + // Driver object reference + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the browser + driver.get("https://www.training-support.net/webelements/dynamic-controls"); + + // Verify page title + System.out.println("Page title is: " + driver.getTitle()); + + // Find the checkbox and make sure it is visible + WebElement checkbox = driver.findElement(By.id("checkbox")); + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Find the button to toggle it and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Wait for it to disappear + wait.until(ExpectedConditions.invisibilityOf(checkbox)); + // Check if it is visible + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Toggle the checkbox and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + wait.until(ExpectedConditions.elementToBeClickable(checkbox)).click(); + // Check if it is selected + System.out.println("Checkbox is selected? " + checkbox.isSelected()); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity11.py b/Selenium/Activities/Activity11.py new file mode 100644 index 0000000000..5806f2607f --- /dev/null +++ b/Selenium/Activities/Activity11.py @@ -0,0 +1,31 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox and make sure it is visible + checkbox = driver.find_element(By.ID, "checkbox") + print("Checkbox is visible? ", checkbox.is_displayed()) + + # Find the button to toggle it and click it + driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']").click() + # Wait for it to disappear + wait.until(EC.invisibility_of_element(checkbox)) + # Check if it is visible + print("Checkbox is visible? ", checkbox.is_displayed()) + + # Toggle the checkbox and click it + driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']").click() + wait.until(EC.element_to_be_clickable(checkbox)).click() + # Check if it is selected + print("Checkbox is selected? ", checkbox.is_selected()) \ No newline at end of file diff --git a/Selenium/Activities/Activity12.java b/Selenium/Activities/Activity12.java new file mode 100644 index 0000000000..58f647c5ee --- /dev/null +++ b/Selenium/Activities/Activity12.java @@ -0,0 +1,31 @@ +package activities; +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity12 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page + driver.get("https://www.training-support.net/webelements/dynamic-content"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the button and click it + driver.findElement(By.id("genButton")).click(); + // Wait for the word to appear + if (wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("word"), "release"))) { + // Print the text to console + System.out.println("Word found: " + driver.findElement(By.id("word")).getText()); + } + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity12.py b/Selenium/Activities/Activity12.py new file mode 100644 index 0000000000..2c4d85c551 --- /dev/null +++ b/Selenium/Activities/Activity12.py @@ -0,0 +1,21 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-content") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the button and click it + driver.find_element(By.ID, "genButton").click() + # Wait for the word to appear + if wait.until(EC.text_to_be_present_in_element((By.ID, "word"), "release")): + # Print the text to console + print("Word found: ", driver.find_element(By.ID, "word").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity13.java b/Selenium/Activities/Activity13.java new file mode 100644 index 0000000000..5b70287e35 --- /dev/null +++ b/Selenium/Activities/Activity13.java @@ -0,0 +1,40 @@ +package activities; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity13 { + public static void main(String[] args) { + // Initialize the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/tables"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Print the number of columns + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + // Print the number of rows + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of rows: " + rows.size()); + + // Print the cells values of the third row + List thirdRow = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[3]/td")); + System.out.println("Third row cell values: "); + for(WebElement cell : thirdRow) { + System.out.println(cell.getText()); + } + + // Print the cell value of the second row and second column + WebElement cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[2]/td[2]")); + System.out.println("Second row, second cell value: " + cellValue.getText()); + + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Selenium/Activities/Activity13.py b/Selenium/Activities/Activity13.py new file mode 100644 index 0000000000..8572b0bdd3 --- /dev/null +++ b/Selenium/Activities/Activity13.py @@ -0,0 +1,27 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/tables") + # Print the title of the page + print("Page title is: ", driver.title) + + # Print the number of columns + cols = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th") + print("Number of columns: ", len(cols)) + # Print the number of rows + rows = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr") + print("Number of rows: ", len(rows)) + + # Print the cells values of the third row + thirdRow = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[3]/td") + print("Third row cell values: ") + for cell in thirdRow: + print(cell.text) + + # Print the cell value of the second row and second column + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[2]/td[2]") + print("Second row, second cell value: ", cellValue.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity14.java b/Selenium/Activities/Activity14.java new file mode 100644 index 0000000000..94009441c1 --- /dev/null +++ b/Selenium/Activities/Activity14.java @@ -0,0 +1,40 @@ +package activities; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity14 { + public static void main(String[] args) { + // Create a new instance of the chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/tables"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Print the number of columns + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + // Print the number of rows + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of rows: " + rows.size()); + + // Print the Book Name in the 5th row + WebElement cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book name before sorting: " + cellValue.getText()); + + // Sort the table + driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th[5]")).click(); + + // Print the cell value of the second row and second column again + cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book Name after sorting: " + cellValue.getText()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity14.py b/Selenium/Activities/Activity14.py new file mode 100644 index 0000000000..5ee498788c --- /dev/null +++ b/Selenium/Activities/Activity14.py @@ -0,0 +1,31 @@ + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +with webdriver.Firefox() as driver: + + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/tables") + # Print the title of the page + print("Page title is: ", driver.title) + + # Print the number of columns + cols = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th") + print("Number of columns: ", len(cols)) + # Print the number of rows + rows = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr") + print("Number of rows: ", len(rows)) + + # Print the Book Name in the 5th row + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]") + print("Book name before sorting: ", cellValue.text) + + # Sort the table + driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th[5]").click() + + # Print the cell value of the second row and second column again + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]") + print("Book Name after sorting: ", cellValue.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity15.java b/Selenium/Activities/Activity15.java new file mode 100644 index 0000000000..244bca426c --- /dev/null +++ b/Selenium/Activities/Activity15.java @@ -0,0 +1,44 @@ +package activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity15 { + public static void main(String[] args) { + // Create a new instance of the chrome driver + WebDriver driver = new ChromeDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page + driver.get("https://training-support.net/webelements/dynamic-attributes"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // Find the input fields + WebElement fullName = driver.findElement(By.xpath("//input[starts-with(@id, 'full-name')]")); + WebElement email = driver.findElement(By.xpath("//input[contains(@id, '-email')]")); + WebElement eventDate = driver.findElement(By.xpath("//input[contains(@name, '-event-date-')]")); + WebElement details = driver.findElement(By.xpath("//textarea[contains(@id, '-additional-details-')]")); + // Enter the details + fullName.sendKeys("Raiden Shogun"); + email.sendKeys("raiden@electromail.com"); + eventDate.sendKeys("2025-06-26"); + details.sendKeys("It will be electric!"); + // Find and click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Wait for the success message and print it + String message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("action-confirmation"))) + .getText(); + System.out.println("Success message: " + message); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity15.py b/Selenium/Activities/Activity15.py new file mode 100644 index 0000000000..4989d07b78 --- /dev/null +++ b/Selenium/Activities/Activity15.py @@ -0,0 +1,30 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-attributes") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the input fields + fullName = driver.find_element(By.XPATH, "//input[starts-with(@id, 'full-name')]") + email = driver.find_element(By.XPATH, "//input[contains(@id, '-email')]") + eventDate = driver.find_element(By.XPATH, "//input[contains(@name, '-event-date-')]") + details = driver.find_element(By.XPATH, "//textarea[contains(@id, '-additional-details-')]") + # Enter the details + fullName.send_keys("Raiden Shogun") + email.send_keys("raiden@electromail.com") + eventDate.send_keys("2025-06-26") + details.send_keys("It will be electric!") + # Find and click the submit button + driver.find_element(By.XPATH, "//button[text()='Submit']").click() + + # Wait for the success message and print it + message = wait.until(EC.visibility_of_element_located((By.ID, "action-confirmation"))).text + print("Success message: ", message) \ No newline at end of file diff --git a/Selenium/Activities/Activity16.java b/Selenium/Activities/Activity16.java new file mode 100644 index 0000000000..a5a6905ad5 --- /dev/null +++ b/Selenium/Activities/Activity16.java @@ -0,0 +1,50 @@ +package activities; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.Select; + +public class Activity16 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/selects"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // Find the dropdown + WebElement dropdown = driver.findElement(By.cssSelector("select.h-10")); + // Pass the WebElement to the Select object + Select singleSelect = new Select(dropdown); + + // Select the second option using visible text + singleSelect.selectByVisibleText("Two"); + // Print the selected option + System.out.println("Second option: " + singleSelect.getFirstSelectedOption().getText()); + + // Select the third option using index + singleSelect.selectByIndex(3); + // Print the selected option + System.out.println("Third option: " + singleSelect.getFirstSelectedOption().getText()); + + // Select the fourth option using value attribute + singleSelect.selectByValue("four"); + // Print the selected option + System.out.println("Fourth option: " + singleSelect.getFirstSelectedOption().getText()); + + // Print all the options + List allOptions = singleSelect.getOptions(); + System.out.println("Options in the dropdown: "); + for(WebElement option : allOptions) { + System.out.println(option.getText()); + } + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity16.py b/Selenium/Activities/Activity16.py new file mode 100644 index 0000000000..be5a21bf9e --- /dev/null +++ b/Selenium/Activities/Activity16.py @@ -0,0 +1,37 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.select import Select + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/selects") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the dropdown + dropdown = driver.find_element(By.CSS_SELECTOR, "select.h-10") + # Pass the WebElement to the Select object + singleSelect = Select(dropdown) + + # Select the second option using visible text + singleSelect.select_by_visible_text("Two") + # Print the selected option + print("Second option: " + singleSelect.first_selected_option.text) + + # Select the third option using index + singleSelect.select_by_index(3) + # Print the selected option + print("Third option: " + singleSelect.first_selected_option.text) + + # Select the fourth option using value attribute + singleSelect.select_by_value("four") + # Print the selected option + print("Fourth option: " + singleSelect.first_selected_option.text) + + # Print all the options + allOptions = singleSelect.options + print("Options in the dropdown: ") + for option in allOptions: + print(option.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity17.java b/Selenium/Activities/Activity17.java new file mode 100644 index 0000000000..548a8c5b8d --- /dev/null +++ b/Selenium/Activities/Activity17.java @@ -0,0 +1,52 @@ +package activities; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.Select; + +public class Activity17 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/selects"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the dropdown + WebElement selectElement = driver.findElement(By.cssSelector("select.h-80")); + // Pass the WebElement to the Select object + Select multiSelect = new Select(selectElement); + + // Select "HTML" using visible text + multiSelect.selectByVisibleText("HTML"); + // Select 4th, 5th, and 6th index options + for (int i = 3; i <= 5; i++) { + multiSelect.selectByIndex(i); + } + // Select "Node" using value attribute + multiSelect.selectByValue("nodejs"); + // Print the selected options + List selectedOptions = multiSelect.getAllSelectedOptions(); + System.out.println("Selected options are: "); + for (WebElement option : selectedOptions) { + System.out.println(option.getText()); + } + + // Deselect the 5th index option + multiSelect.deselectByIndex(4); + // Print the selected options + selectedOptions = multiSelect.getAllSelectedOptions(); + System.out.println("Selected options are: "); + for (WebElement option : selectedOptions) { + System.out.println(option.getText()); + } + + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Selenium/Activities/Activity17.py b/Selenium/Activities/Activity17.py new file mode 100644 index 0000000000..6977750714 --- /dev/null +++ b/Selenium/Activities/Activity17.py @@ -0,0 +1,36 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.select import Select + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/selects") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the dropdown + selectElement = driver.find_element(By.CSS_SELECTOR, "select.h-80") + # Pass the WebElement to the Select object + multiSelect = Select(selectElement) + + # Select "HTML" using visible text + multiSelect.select_by_visible_text("HTML") + # Select 4th, 5th, and 6th index options + for i in range(3, 5): + multiSelect.select_by_index(i) + # Select "Node" using value attribute + multiSelect.select_by_value("nodejs") + # Print the selected options + selectedOptions = multiSelect.all_selected_options + print("Selected options are: ") + for option in selectedOptions: + print(option.text) + + # Deselect the 5th index option + multiSelect.deselect_by_index(4) + # Print the selected options + selectedOptions = multiSelect.all_selected_options + print("Selected options are: ") + for option in selectedOptions: + print(option.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity18.java b/Selenium/Activities/Activity18.java new file mode 100644 index 0000000000..2c088f912a --- /dev/null +++ b/Selenium/Activities/Activity18.java @@ -0,0 +1,37 @@ +package activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity18 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find and click the button to open the alert + driver.findElement(By.id("simple")).click(); + + // Switch focus to the alert + Alert simpleAlert = driver.switchTo().alert(); + + // Print the text in the alert + String alertText = simpleAlert.getText(); + System.out.println("Text in alert: " + alertText); + + // Close the alert by clicking OK + simpleAlert.accept(); + + // Print the message + System.out.println(driver.findElement(By.id("result")).getText()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity18.py b/Selenium/Activities/Activity18.py new file mode 100644 index 0000000000..44772562ba --- /dev/null +++ b/Selenium/Activities/Activity18.py @@ -0,0 +1,30 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "simple").click() + + # Switch focus to the alert + simpleAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = simpleAlert.text + print("Text in alert: " + alertText) + + # Close the alert by clicking OK + simpleAlert.accept() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity19.java b/Selenium/Activities/Activity19.java new file mode 100644 index 0000000000..2be0fa027c --- /dev/null +++ b/Selenium/Activities/Activity19.java @@ -0,0 +1,40 @@ +package activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity19 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find and click the button to open the alert + driver.findElement(By.id("confirm")).click(); + + // Switch focus to the alert + Alert confirmAlert = driver.switchTo().alert(); + + // Print the text in the alert + String alertText = confirmAlert.getText(); + System.out.println("Text in alert: " + alertText); + + // Close the alert by clicking OK + confirmAlert.accept(); + + // Can also close the alert by clicking Cancel + // confirmAlert.dismiss(); + + // Print the message + System.out.println(driver.findElement(By.id("result")).getText()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity19.py b/Selenium/Activities/Activity19.py new file mode 100644 index 0000000000..2816ec0c56 --- /dev/null +++ b/Selenium/Activities/Activity19.py @@ -0,0 +1,29 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "confirmation").click() + + # Switch focus to the alert + confirmAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = confirmAlert.text + print("Text in alert: " + alertText) + + # Close the alert by clicking OK + confirmAlert.dismiss() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity2.java b/Selenium/Activities/Activity2.java new file mode 100644 index 0000000000..02e6dd79d4 --- /dev/null +++ b/Selenium/Activities/Activity2.java @@ -0,0 +1,32 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity2 { + + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/login-form"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the username field and enter the username + driver.findElement(By.id("username")).sendKeys("admin"); + // Find the password field and enter the password + driver.findElement(By.id("password")).sendKeys("password"); + // Find the login button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Print the confirmation message + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println(message); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity2.py b/Selenium/Activities/Activity2.py new file mode 100644 index 0000000000..4ef156f3cb --- /dev/null +++ b/Selenium/Activities/Activity2.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/login-form") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the username field + username = driver.find_element(By.CSS_SELECTOR, "input#username") + # Find the password field + password = driver.find_element(By.ID, "password") + + # Enter the given credentials + # Enter username + username.send_keys("admin") + # Enter password + password.send_keys("password") + + # Find the login button + login = driver.find_element(By.CSS_SELECTOR, "button.svelte-1pdjkmx") + login.click() + + # Print the login message + message = driver.find_element(By.CSS_SELECTOR, "h1.text-center") + print("Login message: ", message.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity20.java b/Selenium/Activities/Activity20.java new file mode 100644 index 0000000000..ce0f8d76f1 --- /dev/null +++ b/Selenium/Activities/Activity20.java @@ -0,0 +1,39 @@ +package activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity20 { + public static void main(String[] args) throws InterruptedException { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find and click the button to open the alert + driver.findElement(By.id("prompt")).click(); + + // Switch focus to the alert + Alert promtAlert = driver.switchTo().alert(); + + // Print the text in the alert + String alertText = promtAlert.getText(); + System.out.println("Text in alert: " + alertText); + // Type into the alert + promtAlert.sendKeys("Awesome!"); + Thread.sleep(5000); + + // Close the alert by clicking OK + promtAlert.accept(); + // Print the message + System.out.println(driver.findElement(By.id("result")).getText()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity20.py b/Selenium/Activities/Activity20.py new file mode 100644 index 0000000000..68c83d5084 --- /dev/null +++ b/Selenium/Activities/Activity20.py @@ -0,0 +1,32 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "prompt").click() + + # Switch focus to the alert + promptAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = promptAlert.text + print("Text in alert: " + alertText) + + # Type text in the prompt alert + promptAlert.send_keys("Awesome!") + + # Close the alert by clicking OK + promptAlert.accept() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity21.java b/Selenium/Activities/Activity21.java new file mode 100644 index 0000000000..f36e3efe54 --- /dev/null +++ b/Selenium/Activities/Activity21.java @@ -0,0 +1,56 @@ +package activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity21 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page + driver.get("https://training-support.net/webelements/tabs"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + // Print the handle of the parent window + System.out.println("Current tab: " + driver.getWindowHandle()); + + // Find button to open new tab + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Open A New Tab']"))).click(); + // Wait for the second tab to open + wait.until(ExpectedConditions.numberOfWindowsToBe(2)); + // Print all window handles + System.out.println("Currently open windows: " + driver.getWindowHandles()); + + // Switch focus to the latest tab + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + + // Wait for the new page to load + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(), 'Another One')]"))); + // Print the handle of the current tab + System.out.println("Current tab: " + driver.getWindowHandle()); + // Print the title and heading of the new page + System.out.println("New Page title: " + driver.getTitle()); + System.out.println("New Page message: " + driver.findElement(By.cssSelector("h2.mt-5")).getText()); + // Find and click the button on page to open another tab + driver.findElement(By.xpath("//button[contains(text(), 'Another One')]")).click(); + + // Wait for new tab to open + wait.until(ExpectedConditions.numberOfWindowsToBe(3)); + // Switch focus + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity21.py b/Selenium/Activities/Activity21.py new file mode 100644 index 0000000000..debf5d3f22 --- /dev/null +++ b/Selenium/Activities/Activity21.py @@ -0,0 +1,40 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/tabs") + # Print the title of the page + print("Page title is: ", driver.title) + # Print the handle of the parent window + print("Current tab: ", driver.current_window_handle) + + # Find button to open new tab + wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open A New Tab']"))).click() + # Wait for the second tab to open + wait.until(EC.number_of_windows_to_be(2)) + # Print all window handles + print("Currently open windows: ", driver.window_handles) + driver.switch_to.window(driver.window_handles[1]) + + # Wait for the new page to load + wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Another One')]"))) + # Print the handle of the current tab + print("Current tab: ", driver.current_window_handle) + # Print the title and heading of the new page + print("New Page title: ", driver.title) + print("New Page message: ", driver.find_element(By.CSS_SELECTOR, "h2.mt-5").text) + # Find and click the button on page to open another tab + driver.find_element(By.XPATH, "//button[contains(text(), 'Another One')]").click() + + # Wait for new tab to open + wait.until(EC.number_of_windows_to_be(3)) + # Switch focus + for handle in driver.window_handles: + driver.switch_to.window(driver.window_handles[2]) \ No newline at end of file diff --git a/Selenium/Activities/Activity22.java b/Selenium/Activities/Activity22.java new file mode 100644 index 0000000000..aca7c02b75 --- /dev/null +++ b/Selenium/Activities/Activity22.java @@ -0,0 +1,44 @@ +package activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity22 { + public static void main(String[] args) { + // Create a new instance of the Chrome driver + WebDriver driver = new ChromeDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + // Open the page + driver.get("https://training-support.net/webelements/popups"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the launcher button and click it + driver.findElement(By.id("launcher")).click(); + + // Wait for the modal to appear + wait.until(ExpectedConditions.elementToBeClickable(By.id("username"))); + + // Find the input fields + WebElement username = driver.findElement(By.id("username")); + WebElement password = driver.findElement(By.id("password")); + // Enter the credentials + username.sendKeys("admin"); + password.sendKeys("password"); + // Click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Print the success message + String message = driver.findElement(By.cssSelector("h2.text-center")).getText(); + System.out.println("Login message: " + message); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity22.py b/Selenium/Activities/Activity22.py new file mode 100644 index 0000000000..6acd7d9081 --- /dev/null +++ b/Selenium/Activities/Activity22.py @@ -0,0 +1,32 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/popups") + # Print the title of the page + print("Page title is: ", driver.title) + # Find the launcher button and click it + driver.find_element(By.ID, "launcher").click() + + # Wait for the modal to appear + wait.until(EC.element_to_be_clickable((By.ID, "username"))) + + # Find the input fields + username = driver.find_element(By.ID, "username") + password = driver.find_element(By.ID, "password") + # Enter the credentials + username.send_keys("admin") + password.send_keys("password") + # Click the submit button + driver.find_element(By.XPATH, "//button[text()='Submit']").click() + + # Print the success message + message = driver.find_element(By.CSS_SELECTOR, "h2.text-center").text + print("Login message: " + message) \ No newline at end of file diff --git a/Selenium/Activities/Activity3.java b/Selenium/Activities/Activity3.java new file mode 100644 index 0000000000..1d122a4328 --- /dev/null +++ b/Selenium/Activities/Activity3.java @@ -0,0 +1,32 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity3 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/login-form"); + // Print the title of the page + System.out.println("Home page title: " + driver.getTitle()); + + // Find the username field and enter the username + driver.findElement(By.xpath("//input[@id='username']")).sendKeys("admin"); + // Find the password field and enter the password + driver.findElement(By.xpath("//input[@id='password']")).sendKeys("password"); + // Find the login button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Print the confirmation message + String message = driver.findElement(By.xpath("//h1[contains(text(), 'Success')]")).getText(); + System.out.println(message); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity3.py b/Selenium/Activities/Activity3.py new file mode 100644 index 0000000000..4f28d634a6 --- /dev/null +++ b/Selenium/Activities/Activity3.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/login-form") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the username field + username = driver.find_element(By.XPATH, "//input[@id='username']") + # Find the password field + password = driver.find_element(By.XPATH, "//input[@id='password']") + + # Enter the given credentials + # Enter username + username.send_keys("admin") + # Enter password + password.send_keys("password") + + # Find the login button + login = driver.find_element(By.XPATH, "//button[text()='Submit']") + login.click() + + # Print the login message + message = driver.find_element(By.XPATH, "//h1[contains(@class, 'text-center')]") + print("Login message: ", message.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity4.java b/Selenium/Activities/Activity4.java new file mode 100644 index 0000000000..cc9bf05dd7 --- /dev/null +++ b/Selenium/Activities/Activity4.java @@ -0,0 +1,36 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.Color; + +public class Activity4 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/target-practice"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the 3rd header and print its text + String thirdHeaderText = driver.findElement(By.xpath("//h3[contains(text(), '#3')]")).getText(); + System.out.println(thirdHeaderText); + // Find the 5th header and print its color + Color fifthHeaderColor = Color.fromString(driver.findElement(By.xpath("//h5[contains(text(), '#5')]")).getCssValue("color")); + System.out.println("Color as RGB: " + fifthHeaderColor.asRgb()); + System.out.println("Color as hexcode: " + fifthHeaderColor.asHex()); + + // Find the violet button and print its classes + String purpleButtonClass = driver.findElement(By.xpath("//button[text()='Purple']")).getDomAttribute("class"); + System.out.println(purpleButtonClass); + // Find the grey button and print its text + String slateButtonText = driver.findElement(By.xpath("//button[contains(@class, 'slate')]")).getText(); + System.out.println(slateButtonText); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity4.py b/Selenium/Activities/Activity4.py new file mode 100644 index 0000000000..54f750a333 --- /dev/null +++ b/Selenium/Activities/Activity4.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.color import Color + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/target-practice") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the 3rd header element on the page using XPath + third_heading = driver.find_element(By.XPATH, "//h3[contains(text(), '#3')]") + print("Third heading text is: ", third_heading.text) + + # Find the 5th header element on the page using XPath + fifth_heading_color = Color.from_string(driver.find_element(By.XPATH, "//h5[contains(text(), '#5')]").value_of_css_property("color")) + print("Fifth heading colour as Hexcode: ", fifth_heading_color.hex) + print("Fifth heading colour as RGB: ", fifth_heading_color.rgb) + + # Find the Purple button element on the page + purple_button = driver.find_element(By.XPATH, "//button[text()='Purple']") + print("Purple button's classes are: ", purple_button.get_attribute("class")) + + # Find the Slate button element on the page + slate_button = driver.find_element(By.XPATH, "//button[contains(@class, 'slate')]") + print("Text in slate button is: ", slate_button.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity5.java b/Selenium/Activities/Activity5.java new file mode 100644 index 0000000000..8cbfd0b680 --- /dev/null +++ b/Selenium/Activities/Activity5.java @@ -0,0 +1,30 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity5 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + // Open the page + driver.get("https://training-support.net/webelements/dynamic-controls"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the checkbox + WebElement checkbox = driver.findElement(By.id("checkbox")); + // Find the toggle button and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Check if it is displayed on the page + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + // Click the button again + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Check if it is displayed on the page + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity5.py b/Selenium/Activities/Activity5.py new file mode 100644 index 0000000000..952ad3ea6c --- /dev/null +++ b/Selenium/Activities/Activity5.py @@ -0,0 +1,23 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + checkbox = driver.find_element(By.ID, "checkbox") + # Find the checkbox toggle button + checkbox_toggle = driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']") + # Verify if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) + + # Click the checkbox_toggle button to hide checkbox + checkbox_toggle.click() + # Verify again if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) \ No newline at end of file diff --git a/Selenium/Activities/Activity6.java b/Selenium/Activities/Activity6.java new file mode 100644 index 0000000000..4fb2f2d711 --- /dev/null +++ b/Selenium/Activities/Activity6.java @@ -0,0 +1,31 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity6 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/dynamic-controls"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the checkbox + WebElement checkbox = driver.findElement(By.id("checkbox")); + // Click it + checkbox.click(); + // Check if it is selected + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + // Click the checkbox again + checkbox.click(); + // Check if it is selected + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity6.py b/Selenium/Activities/Activity6.py new file mode 100644 index 0000000000..952ad3ea6c --- /dev/null +++ b/Selenium/Activities/Activity6.py @@ -0,0 +1,23 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + checkbox = driver.find_element(By.ID, "checkbox") + # Find the checkbox toggle button + checkbox_toggle = driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']") + # Verify if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) + + # Click the checkbox_toggle button to hide checkbox + checkbox_toggle.click() + # Verify again if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) \ No newline at end of file diff --git a/Selenium/Activities/Activity7.java b/Selenium/Activities/Activity7.java new file mode 100644 index 0000000000..ab04ad3306 --- /dev/null +++ b/Selenium/Activities/Activity7.java @@ -0,0 +1,34 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +public class Activity7 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/dynamic-controls"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the text field + WebElement textbox = driver.findElement(By.id("textInput")); + // Check if it is enabled + System.out.println("Input field is enabled: " + textbox.isEnabled()); + // Click the toggle button to enable it + driver.findElement(By.id("textInputButton")).click(); + // Check if the text field is enabled + System.out.println("Input field is enabled: " + textbox.isEnabled()); + + // Type something in to it + textbox.sendKeys("Example text"); + System.out.println(textbox.getDomProperty("value")); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity7.py b/Selenium/Activities/Activity7.py new file mode 100644 index 0000000000..3361768e79 --- /dev/null +++ b/Selenium/Activities/Activity7.py @@ -0,0 +1,20 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + textbox = driver.find_element(By.ID, "textInput") + # Verify if the checkbox is enabled or not + print("Textbox is enabled: ", textbox.is_enabled()) + # Click it again + driver.find_element(By.ID, "textInputButton").click() + # Verify again if the textbox is enabled or not + print("Textbox is enabled: ", textbox.is_enabled()) \ No newline at end of file diff --git a/Selenium/Activities/Activity8.java b/Selenium/Activities/Activity8.java new file mode 100644 index 0000000000..83730f433d --- /dev/null +++ b/Selenium/Activities/Activity8.java @@ -0,0 +1,45 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity8 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + // Create the Actions object + Actions builder = new Actions(driver); + + // Open the page + driver.get("https://training-support.net/webelements/mouse-events"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the elements that can be clicked + WebElement cargoLock = driver.findElement(By.xpath("//h1[text()='Cargo.lock']")); + WebElement cargoToml = driver.findElement(By.xpath("//h1[text()='Cargo.toml']")); + WebElement srcButton = driver.findElement(By.xpath("//h1[text()='src']")); + WebElement targetButton = driver.findElement(By.xpath("//h1[text()='target']")); + + // Perform left click on Cargo.lock and then on Cargo.toml + builder.click(cargoLock).pause(1000).moveToElement(cargoToml).pause(5000).click(cargoToml).build().perform(); + // Print the front side text + String actionMessage = driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + + // Perform double click on src + // then right click on target + builder.doubleClick(srcButton).pause(3000).pause(5000) + .contextClick(targetButton).pause(3000).build().perform(); + // and then open it + builder.click(driver.findElement(By.xpath("//div[@id='menu']/div/ul/li[1]"))).pause(5000).build().perform(); + // Print the front side text + actionMessage = driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity8.py b/Selenium/Activities/Activity8.py new file mode 100644 index 0000000000..376b1160d8 --- /dev/null +++ b/Selenium/Activities/Activity8.py @@ -0,0 +1,34 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/mouse-events") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the elements that can be clicked + cargoLock = driver.find_element(By.XPATH, "//h1[text()='Cargo.lock']") + cargoToml = driver.find_element(By.XPATH, "//h1[text()='Cargo.toml']") + srcButton = driver.find_element(By.XPATH, "//h1[text()='src']") + targetButton = driver.find_element(By.XPATH, "//h1[text()='target']") + + # Perform left click on Cargo.lock and then on Cargo.toml + actions.click(cargoLock).pause(1).move_to_element(cargoToml).pause(5).click(cargoToml).perform() + # Print the front side text + actionMessage = driver.find_element(By.ID, "result").text + print(actionMessage) + + # Perform double click on src then right click on target + actions.double_click(srcButton).pause(3).pause(5).context_click(targetButton).pause(3).perform() + # and then open it + actions.click(driver.find_element(By.XPATH, ("//div[@id='menu']/div/ul/li[1]"))).pause(5).perform() + # Print the front side text + actionMessage = driver.find_element(By.ID, "result").text + print(actionMessage) \ No newline at end of file diff --git a/Selenium/Activities/Activity9.java b/Selenium/Activities/Activity9.java new file mode 100644 index 0000000000..2f058df723 --- /dev/null +++ b/Selenium/Activities/Activity9.java @@ -0,0 +1,31 @@ +package activities; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity9 { + public static void main(String[] args) { + // Initialize the chrome Driver + WebDriver driver = new ChromeDriver(); + // Create the Actions object + Actions builder = new Actions(driver); + + // Open the page + driver.get("https://training-support.net/webelements/keyboard-events"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Press the key + builder.sendKeys("This is coming from Selenium").sendKeys(Keys.RETURN).build().perform(); + + // Print the message from the page + String pageText = driver.findElement(By.cssSelector("h1.mt-3")).getText(); + System.out.println(pageText); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity9.py b/Selenium/Activities/Activity9.py new file mode 100644 index 0000000000..cd332e29b4 --- /dev/null +++ b/Selenium/Activities/Activity9.py @@ -0,0 +1,21 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import Keys, ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/keyboard-events") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Press the key + actions.send_keys("This is coming from Selenium").send_keys(Keys.RETURN).perform() + + # Print the message from the page + pageText = driver.find_element(By.CSS_SELECTOR, "h1.mt-3").text + print(pageText) \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity1.java b/Selenium/Project/CRM_Activity1.java new file mode 100644 index 0000000000..5c66985952 --- /dev/null +++ b/Selenium/Project/CRM_Activity1.java @@ -0,0 +1,36 @@ +package Project; + + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CRM_Activity1 { + + WebDriver driver; + + @BeforeClass + public void setUp() { + + driver = new ChromeDriver(); + driver.get("http://alchemy.hguy.co/crm"); + } + + // Test function + @Test(priority = 1) + public void homePageTest() { + + Assert.assertEquals(driver.getTitle(), "SuiteCRM"); + + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + + +} diff --git a/Selenium/Project/CRM_Activity1.py b/Selenium/Project/CRM_Activity1.py new file mode 100644 index 0000000000..bd9b332f8a --- /dev/null +++ b/Selenium/Project/CRM_Activity1.py @@ -0,0 +1,20 @@ +# Goal: Read the title of the website and verify the text + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") +# Get the title of the website. +# Make sure it matches “SuiteCRM” exactly + + if(driver.title=="SuiteCRM"): + print ("The Page title is : ",driver.title) + else: + print ("Wrong Page opened ! ") + +# close the browser. + driver.quit() diff --git a/Selenium/Project/CRM_Activity2.java b/Selenium/Project/CRM_Activity2.java new file mode 100644 index 0000000000..22d7d94606 --- /dev/null +++ b/Selenium/Project/CRM_Activity2.java @@ -0,0 +1,50 @@ +package Project; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +public class CRM_Activity2 { + + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + + + driver.get("http://alchemy.hguy.co/crm"); + } + + + // Test function + @Test(priority = 1) + public void headerImageURL() { + + //Get the URL of the header image + WebElement headerImage = driver.findElement(By.xpath("//div/img")); + //Print the URL to the console + String actualUrl =headerImage.getDomAttribute("src"); + + System.out.println("The URL of image is " + actualUrl); + + String expectedUrl = "themes/default/images/company_logo.png?v=cK7kLsY0ftg72ZVHTYUT_g"; + Assert.assertEquals(actualUrl, expectedUrl); + + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + + +} diff --git a/Selenium/Project/CRM_Activity2.py b/Selenium/Project/CRM_Activity2.py new file mode 100644 index 0000000000..54e8e57e46 --- /dev/null +++ b/Selenium/Project/CRM_Activity2.py @@ -0,0 +1,19 @@ +# Get the url of the header image +# Goal: Print the url of the header image to the console +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Get the url of the header image. +# Print the url to the console. + headerImage = driver.find_element(By.XPATH, "//div/img") + actualUrl = headerImage.get_attribute("src") + print("The url in Image is : " + actualUrl) +# Close the browser + driver.quit() + diff --git a/Selenium/Project/CRM_Activity3.java b/Selenium/Project/CRM_Activity3.java new file mode 100644 index 0000000000..e150574587 --- /dev/null +++ b/Selenium/Project/CRM_Activity3.java @@ -0,0 +1,35 @@ +package Project; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CRM_Activity3 { + + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void copyrightText() { + + String textCR = driver.findElement(By.id("admin_options")).getText(); + System.out.println("The first copyright text is : " + textCR); + } + + + @AfterClass + public void tearDown() { + driver.quit(); + } +} diff --git a/Selenium/Project/CRM_Activity3.py b/Selenium/Project/CRM_Activity3.py new file mode 100644 index 0000000000..af9ecc2b05 --- /dev/null +++ b/Selenium/Project/CRM_Activity3.py @@ -0,0 +1,20 @@ +# Get the copyright text +# Goal: Print the first copyright text in the footer to the console + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Chrome() as driver: + +# Navigate + driver.get("https://alchemy.hguy.co/crm/") + +# Get the first copyright text in the footer + copyrightText = driver.find_element(By.ID, "admin_options").text +# Print the text to the console. + print("The text in the Copyright in Footer is : ", copyrightText) + +# Close the browser + driver.quit() \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity4.java b/Selenium/Project/CRM_Activity4.java new file mode 100644 index 0000000000..e7fe05fa27 --- /dev/null +++ b/Selenium/Project/CRM_Activity4.java @@ -0,0 +1,42 @@ +package Project; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +public class CRM_Activity4 { + + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void homepageLogin() throws InterruptedException { + //Provide username and password + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + //Find the submit button and click it + driver.findElement(By.xpath("//input[@type='submit']")).click(); + Thread.sleep(5000); + String homePage = driver.findElement(By.id("tab0")).getText(); + Assert.assertEquals(homePage, "SUITECRM DASHBOARD"); + + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + +} diff --git a/Selenium/Project/CRM_Activity4.py b/Selenium/Project/CRM_Activity4.py new file mode 100644 index 0000000000..0de27d6292 --- /dev/null +++ b/Selenium/Project/CRM_Activity4.py @@ -0,0 +1,25 @@ +# Logging into the site +# Goal: Open the site and login with the credentials provided + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find and select the username and password fields +# Enter login credentials into the respective fields + driver.find_element(By.ID,"user_name").send_keys("admin") + driver.find_element(By.ID,"username_password").send_keys("pa$$w0rd") + driver.find_element(By.ID,"bigbutton").click() + homePageHeader = driver.find_element(By.ID,"tab0").text + # print(homePageHeader) +if(homePageHeader=="SUITECRM DASHBOARD"): + print("Home Page Opened Successfully !") +else: + print("Login failed !") +# Close the browser +driver.quit() \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity5.java b/Selenium/Project/CRM_Activity5.java new file mode 100644 index 0000000000..f1c15572c4 --- /dev/null +++ b/Selenium/Project/CRM_Activity5.java @@ -0,0 +1,53 @@ +package Project; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.Color; +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; + +public class CRM_Activity5 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void loginFormTest() { + //Provide username and password + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + //Find the submit button and click it + driver.findElement(By.xpath("//input[@type='submit']")).click(); + + } + + // Test function + @Test(priority = 2) + public void colorNavMenu() throws InterruptedException { + Thread.sleep(5000); + //Get the color of navigation menu + driver.manage().window().maximize(); + Color navMenuColor = Color.fromString(driver.findElement(By.xpath("//div[@id='toolbar']")).getCssValue("color")); + System.out.println("Color as RGB: " + navMenuColor.asRgb()); + System.out.println("Color as hexcode: " + navMenuColor.asHex()); + + } + + + @AfterClass + public void tearDown() { + driver.quit(); + } + +} diff --git a/Selenium/Project/CRM_Activity5.py b/Selenium/Project/CRM_Activity5.py new file mode 100644 index 0000000000..f1d6e34e32 --- /dev/null +++ b/Selenium/Project/CRM_Activity5.py @@ -0,0 +1,32 @@ +# Getting colors +# Goal: Get the color of the navigation menu + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.color import Color + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find and select the username and password fields +# Enter login credentials into the respective fields + driver.find_element(By.ID,"user_name").send_keys("admin") + driver.find_element(By.ID,"username_password").send_keys("pa$$w0rd") + driver.find_element(By.ID,"bigbutton").click() + homePageHeader = driver.find_element(By.ID,"tab0").text + # print(homePageHeader) + if(homePageHeader=="SUITECRM DASHBOARD"): + print("Home Page Opened Successfully !") + else: + print("Login failed !") + +# Get the color of the navigation menu and print it to the console. + nav_menu_color = Color.from_string(driver.find_element(By.ID, "toolbar").value_of_css_property("color")) + print("Navigation Menu colour as Hexcode: ", nav_menu_color.hex) + print("Navigation Menu colour as RGB: ", nav_menu_color.rgb) + +# Close the browser + driver.quit() \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity6.java b/Selenium/Project/CRM_Activity6.java new file mode 100644 index 0000000000..1c949d5a0b --- /dev/null +++ b/Selenium/Project/CRM_Activity6.java @@ -0,0 +1,60 @@ +package Project; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +public class CRM_Activity6 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + + + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void loginFormTest() { + //Provide username and password + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + //Find the submit button and click it + driver.findElement(By.xpath("//input[@type='submit']")).click(); + + + } + + + //Ensure that the “Activities” menu item exists + + @Test(priority = 2) + public void locateMenu() throws InterruptedException { + Thread.sleep(5000); + driver.manage().window().maximize(); + + WebElement activitiesMenu = driver.findElement(By.id("grouptab_3")); + String textAct = activitiesMenu.getText(); + Thread.sleep(5000); + System.out.println("The Menu has " + textAct); + Assert.assertTrue(activitiesMenu.isEnabled()); + + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + +} diff --git a/Selenium/Project/CRM_Activity6.py b/Selenium/Project/CRM_Activity6.py new file mode 100644 index 0000000000..486c7088f8 --- /dev/null +++ b/Selenium/Project/CRM_Activity6.py @@ -0,0 +1,32 @@ +# Menu checking +# Goal: Make sure that the “Activities” menu item exists and is clickable + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find and select the username and password fields +# Enter login credentials into the respective fields + driver.find_element(By.ID,"user_name").send_keys("admin") + driver.find_element(By.ID,"username_password").send_keys("pa$$w0rd") + driver.find_element(By.ID,"bigbutton").click() + homePageHeader = driver.find_element(By.ID,"tab0").text + # print(homePageHeader) + if(homePageHeader=="SUITECRM DASHBOARD"): + print("Home Page Opened Successfully !") + else: + print("Login failed !") + +# Locate the navigation menu. +# Ensure that the “Activities” menu item exists + driver.fullscreen_window() + activitiesMenu = driver.find_element(By.ID, "grouptab_3") + print("Activities Menu is visible? ", activitiesMenu.is_displayed()) + +# Close the browser + driver.quit() \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity7.java b/Selenium/Project/CRM_Activity7.java new file mode 100644 index 0000000000..494d055bd0 --- /dev/null +++ b/Selenium/Project/CRM_Activity7.java @@ -0,0 +1,60 @@ +package Project; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +public class CRM_Activity7 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //Open a browser + driver = new ChromeDriver(); + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void loginFormTest() { + //Provide username and password + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + //Find the submit button and click it + driver.findElement(By.xpath("//input[@type='submit']")).click(); + + + } + + @Test(priority = 2) + public void additionalInformation() throws InterruptedException { + driver.manage().window().maximize(); +// Navigate to Sales -> Leads + driver.findElement(By.id("grouptab_0")).click(); + driver.findElement(By.id("moduleTab_9_Leads")).click(); + Thread.sleep(2000); +// In the table, find the Additional information icon at the end of the row of the lead information. Click it. + driver.findElement(By.xpath("//span[@title='Additional Details']")).click(); + Thread.sleep(2000); +// Read the popup and print the phone number displayed in it. + WebElement additionalDetails = driver.findElement(By.xpath("//span[@class='phone']")); + String mobileNumber = additionalDetails.getText(); + System.out.println("The mobile number is :" + mobileNumber); + Assert.assertFalse(mobileNumber.isEmpty(),"Mobile Number not available"); + + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + +} diff --git a/Selenium/Project/CRM_Activity7.py b/Selenium/Project/CRM_Activity7.py new file mode 100644 index 0000000000..3ef4fe9d32 --- /dev/null +++ b/Selenium/Project/CRM_Activity7.py @@ -0,0 +1,41 @@ +# Reading additional information +# Goal: Reading a popup that contains additional information about the account/lead. +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find the username field + username = driver.find_element(By.ID, "user_name") +# Find the password field + password = driver.find_element(By.ID, "username_password") + + # Enter the given credentials + # Enter username + username.send_keys("admin") + # Enter password + password.send_keys("pa$$w0rd") + + # Find the login button + login = driver.find_element(By.XPATH, "//input[@type='submit']") + login.click() + + #Function + driver.maximize_window() + time.sleep(2) + + salesMenu = driver.find_element(By.ID, "grouptab_0") + salesMenu.click() + + leadsMenu = driver.find_element(By.ID, "moduleTab_9_Leads") + leadsMenu.click() + time.sleep(2) + addDetIcon = driver.find_element(By.XPATH, "//span[@title='Additional Details']").click() + time.sleep(2) + mobileNumb =driver.find_element(By.XPATH, "//span[@class='phone']").text + print("The mobile number is :" + mobileNumb) \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity8.java b/Selenium/Project/CRM_Activity8.java new file mode 100644 index 0000000000..3ca5a94d39 --- /dev/null +++ b/Selenium/Project/CRM_Activity8.java @@ -0,0 +1,86 @@ +package Project; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +//Traversing tables +//Goal: Open the accounts page and print the contents of the table + +public class CRM_Activity8 { + WebDriver driver; + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Set up method : Open a browser + @BeforeClass + public void setUp() { + // Initialize Chrome driver + driver = new ChromeDriver(); + // Navigate to ‘http://alchemy.hguy.co/crm’. + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void login() { + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + driver.findElement(By.id("bigbutton")).click(); + String homePageUrl = driver.getCurrentUrl(); + Assert.assertTrue(homePageUrl.contains("Home"), "Login Failed !"); + + } + + @Test(priority = 2) + public void openAccountsPage() throws InterruptedException { + driver.manage().window().maximize(); +// Navigate to the Sales -> Accounts page + driver.findElement(By.id("grouptab_0")).click(); + driver.findElement(By.id("moduleTab_9_Accounts")).click(); + Thread.sleep(2000); + String actualAccountsPageHeading = driver.findElement(By.xpath("//h2[@class='module-title-text']")).getText() + .strip(); + String expectedAccountsPageHeading = "ACCOUNTS"; + Assert.assertEquals(actualAccountsPageHeading, expectedAccountsPageHeading); + } + + @Test(priority = 3) + public void getAccountNames() throws InterruptedException { + + // create an empty list and add expected Account Names + List expectedAccountNames = new ArrayList(); + expectedAccountNames.add("5D Investments"); + expectedAccountNames.add("A.D. Importing Company Inc"); + expectedAccountNames.add("AtoZ Co Ltd"); + expectedAccountNames.add("B.H. Edwards Inc"); + expectedAccountNames.add("Calm Sailing Inc"); + // System.out.println("list1:" + expectedAccountNames); + +// Find the table on the page and print the names of the first 5 odd-numbered rows of the table to the console + List namesList = driver + .findElements(By.xpath("//table[@class='list view table-responsive']/tbody/tr/td[3]")); + List actualAccountNames = new ArrayList(); + // Start from index 1 and increment by 2 until index 9 + for (int i = 1; i < 10; i += 2) { + actualAccountNames.add(namesList.get(i).getText()); + } + // System.out.print("list2:" + actualAccountNames); + Assert.assertEquals(actualAccountNames, expectedAccountNames); + } + + @AfterClass + public void tearDown() { + // Close the browser. + driver.close(); + } + +} \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity8.py b/Selenium/Project/CRM_Activity8.py new file mode 100644 index 0000000000..0bed55c349 --- /dev/null +++ b/Selenium/Project/CRM_Activity8.py @@ -0,0 +1,46 @@ +# Traversing tables +# Goal: Open the accounts page and print the contents of the table. + + +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find and select the username and password fields +# Enter login credentials into the respective fields + driver.find_element(By.ID,"user_name").send_keys("admin") + driver.find_element(By.ID,"username_password").send_keys("pa$$w0rd") + driver.find_element(By.ID,"bigbutton").click() + homePageHeader = driver.find_element(By.ID,"tab0").text + # print(homePageHeader) + if(homePageHeader=="SUITECRM DASHBOARD"): + print("Home Page Opened Successfully !") + else: + print("Login failed !") + +# Navigate to the Sales -> Accounts page + driver.fullscreen_window() + driver.find_element(By.ID,"grouptab_0").click() + driver.find_element(By.ID,"moduleTab_9_Accounts").click() + time.sleep(2) +# Find the table on the page and print the names of the first 5 odd-numbered rows of the table to the console + print("The first 5 Odd-numbered names are : ") + namesList = driver.find_elements(By.XPATH,"//table[@class='list view table-responsive']/tbody/tr/td[3]") + for x in range(1, 10, 2): + print(x,namesList[x].text) + +#Close the browser + driver.quit() + + + + + + + \ No newline at end of file diff --git a/Selenium/Project/CRM_Activity9.java b/Selenium/Project/CRM_Activity9.java new file mode 100644 index 0000000000..13bd63fb8e --- /dev/null +++ b/Selenium/Project/CRM_Activity9.java @@ -0,0 +1,105 @@ +package Project; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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; + +public class CRM_Activity9 { + + WebDriver driver; + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Set up method : Open a browser + @BeforeClass + public void setUp() { + // Initialize Chrome driver + driver = new ChromeDriver(); + // Navigate to ‘http://alchemy.hguy.co/crm’. + driver.get("http://alchemy.hguy.co/crm"); + } + + @Test(priority = 1) + public void login() { + driver.findElement(By.id("user_name")).sendKeys("admin"); + driver.findElement(By.id("username_password")).sendKeys("pa$$w0rd"); + driver.findElement(By.id("bigbutton")).click(); + String homePageUrl = driver.getCurrentUrl(); + Assert.assertTrue(homePageUrl.contains("Home"), "Login Failed !"); + + } + + + @Test(priority = 2) + public void getLeadsNameAndUser() throws InterruptedException { + driver.manage().window().maximize(); + + // create an empty list and add expected Leads Names + List expectedLeadsNames= new ArrayList(); + expectedLeadsNames.add("Miss second Name activity"); + expectedLeadsNames.add("Miss Test12 activity"); + expectedLeadsNames.add("Miss Test17 activity"); + expectedLeadsNames.add("Miss Test20 activity"); + expectedLeadsNames.add("Miss Test31 activity"); + expectedLeadsNames.add("Miss Test38 activity"); + expectedLeadsNames.add("Miss Test39 activity"); + expectedLeadsNames.add("Miss Test39 activity"); + expectedLeadsNames.add("Miss Test41 activity"); + expectedLeadsNames.add("Miss Test64 activity"); +// System.out.println("list1:" + expectedLeadsNames); + + // create an empty list and add expected Leads Users + List expectedLeadsUsers = new ArrayList(); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("admin"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("admin"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("chris"); + expectedLeadsUsers.add("admin"); +// System.out.println("list2:" + expectedLeadsUsers); + + +// Navigate to the Sales -> Accounts page + driver.findElement(By.id("grouptab_0")).click(); + driver.findElement(By.id("moduleTab_9_Leads")).click(); + Thread.sleep(2000); + String actualPageTitle = driver.findElement(By.className("module-title-text")).getText().strip(); + String expectedPageTitle = "LEADS"; + Assert.assertEquals(actualPageTitle, expectedPageTitle); + List names =driver.findElements(By.xpath("//table[@class='list view table-responsive']/tbody/tr/td[3]")); + List users =driver.findElements(By.xpath("//table[@class='list view table-responsive']/tbody/tr/td[8]")); + List actualLeadsNames = new ArrayList(); + List actualLeadsUsers = new ArrayList(); + for(int i=1;i<10;i++) { + actualLeadsNames.add(names.get(i).getText()); + actualLeadsUsers.add(users.get(i).getText()); + } + System.out.println("list1:" + actualLeadsNames); + System.out.println("list2:" + actualLeadsUsers); + Assert.assertEquals(actualLeadsNames, expectedLeadsNames); + Assert.assertEquals(actualLeadsUsers, expectedLeadsUsers); + + } + + @AfterClass + public void tearDown() { + // Close the browser. + driver.close(); + } + + + +} diff --git a/Selenium/Project/CRM_Activity9.py b/Selenium/Project/CRM_Activity9.py new file mode 100644 index 0000000000..0d42afb698 --- /dev/null +++ b/Selenium/Project/CRM_Activity9.py @@ -0,0 +1,36 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +# Start the Driver +with webdriver.Chrome() as driver: + + driver.get("https://alchemy.hguy.co/crm/") + +# Find and select the username and password fields +# Enter login credentials into the respective fields + driver.find_element(By.ID,"user_name").send_keys("admin") + driver.find_element(By.ID,"username_password").send_keys("pa$$w0rd") + driver.find_element(By.ID,"bigbutton").click() + homePageHeader = driver.find_element(By.ID,"tab0").text + # print(homePageHeader) + if(homePageHeader=="SUITECRM DASHBOARD"): + print("Home Page Opened Successfully !") + else: + print("Login failed !") + +# Navigate to the Sales -> Leads page + driver.fullscreen_window() + driver.find_element(By.ID,"grouptab_0").click() + driver.find_element(By.ID,"moduleTab_9_Leads").click() + time.sleep(2) +# Find the table on the page and print the names of the first 5 odd-numbered rows of the table to the console + print("The first ten Leads names and users are : ") + leadsNames = driver.find_elements(By.XPATH,"//table[@class='list view table-responsive']/tbody/tr/td[3]") + leadsUsers = driver.find_elements(By.XPATH,"//table[@class='list view table-responsive']/tbody/tr/td[8]") + for x in range(1, 11, 1): + print(x,leadsNames[x].text,":",leadsUsers[x].text) + +#Close the browser + driver.quit() \ No newline at end of file From c68d9e2c443c83dda14032b013931354643c8bc2 Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Tue, 18 Feb 2025 08:38:23 +0530 Subject: [PATCH 5/6] added TestNG Activities --- TestNG/Activities/Activity1.java | 46 ++++++++++++ TestNG/Activities/Activity10.java | 106 +++++++++++++++++++++++++++ TestNG/Activities/Activity2.java | 59 +++++++++++++++ TestNG/Activities/Activity3.java | 47 ++++++++++++ TestNG/Activities/Activity4.java | 15 ++++ TestNG/Activities/Activity4a.java | 10 +++ TestNG/Activities/Activity5.java | 64 ++++++++++++++++ TestNG/Activities/Activity6.java | 59 +++++++++++++++ TestNG/Activities/Activity7.java | 65 +++++++++++++++++ TestNG/Activities/Activity9.java | 117 ++++++++++++++++++++++++++++++ TestNG/Activities/testing.xml | 23 ++++++ 11 files changed, 611 insertions(+) create mode 100644 TestNG/Activities/Activity1.java create mode 100644 TestNG/Activities/Activity10.java create mode 100644 TestNG/Activities/Activity2.java create mode 100644 TestNG/Activities/Activity3.java create mode 100644 TestNG/Activities/Activity4.java create mode 100644 TestNG/Activities/Activity4a.java create mode 100644 TestNG/Activities/Activity5.java create mode 100644 TestNG/Activities/Activity6.java create mode 100644 TestNG/Activities/Activity7.java create mode 100644 TestNG/Activities/Activity9.java create mode 100644 TestNG/Activities/testing.xml diff --git a/TestNG/Activities/Activity1.java b/TestNG/Activities/Activity1.java new file mode 100644 index 0000000000..79922f0563 --- /dev/null +++ b/TestNG/Activities/Activity1.java @@ -0,0 +1,46 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class Activity1 { + + WebDriver driver; + + // Setup function + @BeforeClass + public void setUp() { + + driver = new ChromeDriver(); + driver.get("https://training-support.net"); + } + + // Test function + @Test(priority = 1) + public void homePageTest() { + Assert.assertEquals(driver.getTitle(), "Training Support"); + + // Find and click the About page link + driver.findElement(By.linkText("About Us")).click(); + } + + @Test(priority = 2) + public void aboutPageTest() { + // Assert page title + Assert.assertEquals(driver.getTitle(), "About Training Support"); + } + + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } + + +} diff --git a/TestNG/Activities/Activity10.java b/TestNG/Activities/Activity10.java new file mode 100644 index 0000000000..7704d8b987 --- /dev/null +++ b/TestNG/Activities/Activity10.java @@ -0,0 +1,106 @@ +package activities; + +import static org.testng.Assert.assertEquals; +import java.io.FileInputStream; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class Activity10 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + driver = new ChromeDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open browser + driver.get("https://training-support.net/webelements/simple-form"); + } + + public static List> readExcel(String filePath) { + List> data = new ArrayList>(); + try { + FileInputStream file = new FileInputStream(filePath); + + // Create Workbook instance holding reference to Excel file + XSSFWorkbook workbook = new XSSFWorkbook(file); + + // Get first sheet from the workbook + XSSFSheet sheet = workbook.getSheetAt(0); + + // Iterate through each rows one by one + for (Row cells : sheet) { + // Temp variable + List rowData = new ArrayList(); + for (Cell cell : cells) { + // Store row data + rowData.add(cell.getStringCellValue()); + } + // Store row data in List + data.add(rowData); + } + file.close(); + workbook.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return data; + } + + @DataProvider(name = "Events") + public static Object[][] signUpInfo() { + String filePath = "src/test/resources/Sample.xlsx"; + List> data = readExcel(filePath); + return new Object[][] { + { data.get(1) }, + { data.get(2) }, + { data.get(3) } + }; + } + + @Test(dataProvider = "Events") + public void registerTest(List rows) throws InterruptedException { + // Find the input fields and enter text + WebElement fullName = driver.findElement(By.id("full-name")); + fullName.sendKeys(rows.get(0)); + + // Enter the email + driver.findElement(By.id("email")).sendKeys(rows.get(1)); + + // Enter the Date of the event + driver.findElement(By.name("event-date")).sendKeys(rows.get(2).replaceAll("\"", "")); + + // Enter additional details + driver.findElement(By.id("additional-details")).sendKeys(rows.get(3)); + + // Click Submit + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Confirm booking + String message = driver.findElement(By.id("action-confirmation")).getText(); + assertEquals(message, "Your event has been scheduled!"); + + driver.navigate().refresh(); + } + + @AfterClass + public void tearDown() { + + driver.quit(); + } +} diff --git a/TestNG/Activities/Activity2.java b/TestNG/Activities/Activity2.java new file mode 100644 index 0000000000..518efda48f --- /dev/null +++ b/TestNG/Activities/Activity2.java @@ -0,0 +1,59 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.SkipException; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class Activity2 { + WebDriver driver; + + @BeforeTest + public void beforeMethod() { + // Create a new instance of the Firefox driver + driver = new ChromeDriver(); + + // Open the browser + driver.get("https://training-support.net/webelements/target-practice"); + } + + @Test + public void testCase1() { + // This test case will pass + String title = driver.getTitle(); + System.out.println("Title is: " + title); + Assert.assertEquals(title, "Selenium: Target Practice"); + } + + @Test + public void testCase2() { + // This test case will Fail + WebElement blackButton = driver.findElement(By.cssSelector("button.black")); + Assert.assertTrue(blackButton.isDisplayed()); + Assert.assertEquals(blackButton.getText(), "black"); + } + + @Test(enabled = false) + public void testCase3() { + // This test will be skipped and not counted + String subHeading = driver.findElement(By.className("sub")).getText(); + Assert.assertTrue(subHeading.contains("Practice")); + } + + @Test + public void testCase4() { + // This test will be skipped and will be be shown as skipped + throw new SkipException("Skipping test case"); + } + + @AfterTest + public void afterMethod() { + // Close the browser + driver.close(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity3.java b/TestNG/Activities/Activity3.java new file mode 100644 index 0000000000..9dfdc75ba0 --- /dev/null +++ b/TestNG/Activities/Activity3.java @@ -0,0 +1,47 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; +import static org.testng.Assert.assertEquals; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.annotations.AfterClass; +public class Activity3 { + + WebDriver driver; //declared outside the function, because we can use it in any no. of functions. + + @BeforeClass + public void setUp() { + + driver = new ChromeDriver(); + //Open the page + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test (priority = 1) + public void pageTitleTest() { + //Get the page title + //String pageTitle = driver.getTitle(); + //Get the page title and verify it + assertEquals(driver.getTitle(), "Selenium: Login Form"); + } + + @Test(priority = 2) + public void loginFormTest() { + //Find the login input fields - username and password + driver.findElement(By.id("username")).sendKeys("admin"); + driver.findElement(By.id("password")).sendKeys("password"); + //Find the submit button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + //verify the login message + String message = driver.findElement(By.tagName("h2")).getText(); + assertEquals(message, "Welcome Back, Admin!"); + } + @AfterClass + public void tearDown() { + //close the browser + driver.quit(); + } +} diff --git a/TestNG/Activities/Activity4.java b/TestNG/Activities/Activity4.java new file mode 100644 index 0000000000..d926768d1d --- /dev/null +++ b/TestNG/Activities/Activity4.java @@ -0,0 +1,15 @@ +package activities; + +import org.testng.annotations.Test; + +public class Activity4 { + @Test + public void firstTestCase() { + System.out.println("I'm in first test case from demoOne Class"); + } + + @Test + public void secondTestCase() { + System.out.println("I'm in second test case from demoOne Class"); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity4a.java b/TestNG/Activities/Activity4a.java new file mode 100644 index 0000000000..869f0e693b --- /dev/null +++ b/TestNG/Activities/Activity4a.java @@ -0,0 +1,10 @@ +package activities; + +import org.testng.annotations.Test; + +public class Activity4a { + @Test + public void TestCase() { + System.out.println("I'm in the test case from DemoTwo Class"); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity5.java b/TestNG/Activities/Activity5.java new file mode 100644 index 0000000000..c649cc130f --- /dev/null +++ b/TestNG/Activities/Activity5.java @@ -0,0 +1,64 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.Color; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class Activity5 { + WebDriver driver; + + // Include alwaysRun property on the @BeforeClass to make sure the page always + // opens + @BeforeClass(alwaysRun = true) + public void setUp() { + + driver = new ChromeDriver(); + driver.get("https://training-support.net/webelements/target-practice"); + } + + @Test(groups = { "HeaderTests", "ButtonTests" }) + public void pageTitleTest() { + String title = driver.getTitle(); + System.out.println("Title is: " + title); + Assert.assertEquals(title, "Selenium: Target Practice"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "HeaderTests" }) + public void HeaderTest1() { + WebElement header3 = driver.findElement(By.xpath("//h3[contains(@class, 'orange')]")); + Assert.assertEquals(header3.getText(), "Heading #3"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "HeaderTests" }) + public void HeaderTest2() { + Color header5Color = Color.fromString(driver.findElement(By.xpath("//h5[contains(text(), 'Heading #5')]")).getCssValue("color")); + Assert.assertEquals(header5Color.asHex(), "#9333ea"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "ButtonTests" }) + public void ButtonTest1() { + WebElement button1 = driver.findElement(By.xpath("//button[contains(@class, 'emerald')]")); + ; + Assert.assertEquals(button1.getText(), "Emerald"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "ButtonTests" }) + public void ButtonTest2() { + Color button2Color = Color + .fromString(driver.findElement(By.xpath("//button[contains(@class, 'teal')]")).getCssValue("color")); + Assert.assertEquals(button2Color.asHex(), "#134e4a"); + } + + // Include alwaysRun property on the @AfterClass to make sure the page always + // closes + @AfterClass(alwaysRun = true) + public void tearDown() { + driver.close(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity6.java b/TestNG/Activities/Activity6.java new file mode 100644 index 0000000000..bd0fa6b06e --- /dev/null +++ b/TestNG/Activities/Activity6.java @@ -0,0 +1,59 @@ +package activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +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.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class Activity6 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + // Initialize the Chrome driver + driver = new ChromeDriver(); + // Initialize the wait object + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open browser + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test + @Parameters({ "username", "password", "message" }) + public void loginTestCase(String username, String password, @Optional("Login Success!") String message) { + // Find username and password fields + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + + // Enter credentials + usernameField.sendKeys(username); + passwordField.sendKeys(password); + + // Click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Wait for the success page to load + wait.until(ExpectedConditions.titleContains("Success")); + + // Assert login message + String loginMessage = driver.findElement(By.cssSelector("h2.text-center")).getText(); + Assert.assertEquals("Welcome Back, Admin!", loginMessage); + } + + @AfterClass + public void afterClass() { + // Close browser + driver.close(); + } +} diff --git a/TestNG/Activities/Activity7.java b/TestNG/Activities/Activity7.java new file mode 100644 index 0000000000..c79f894c96 --- /dev/null +++ b/TestNG/Activities/Activity7.java @@ -0,0 +1,65 @@ +package activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class Activity7 { + WebDriver driver; + WebDriverWait wait; + + @BeforeMethod + public void setUp() { + // Initialize driver + driver = new ChromeDriver(); + // Initialize wait + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + // Open the page + driver.get("https://training-support.net/webelements/login-form"); + } + + @DataProvider(name = "Credentials") + public static Object[][] creds() { + return new Object[][] { + { "admin", "password", "Welcome Back, Admin!" }, + { "wrongAdmin", "wrongPassword", "Invalid Credentials" } + }; + } + + + + @Test(dataProvider = "Credentials") + public void loginTest(String username, String password, String expectedMessage) { + // Find the input fields and the login button + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + WebElement loginButton = driver.findElement(By.xpath("//button[text()='Submit']")); + + // Clear the input fields + usernameField.clear(); + passwordField.clear(); + + // Enter the credentials and click Log in + usernameField.sendKeys(username); + passwordField.sendKeys(password); + loginButton.click(); + + // Assert login message + String loginMessage = driver.findElement(By.cssSelector("h2.text-center")).getText(); + Assert.assertEquals(loginMessage, expectedMessage); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity9.java b/TestNG/Activities/Activity9.java new file mode 100644 index 0000000000..8cee14e667 --- /dev/null +++ b/TestNG/Activities/Activity9.java @@ -0,0 +1,117 @@ +package activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.Reporter; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class Activity9 { + WebDriver driver; + + @BeforeClass + public void setUp() { + driver = new ChromeDriver(); + + Reporter.log("Starting Test |"); + // Open browser + driver.get("https://training-support.net/webelements/alerts"); + Reporter.log("Opened Browser |"); + + // Print title of page + Reporter.log("Page title is " + driver.getTitle() + " |"); + } + + @BeforeMethod + public void beforeMethod() { + Reporter.log("Test Case Setup started |"); + driver.switchTo().defaultContent(); + } + + @Test(priority = 1) + public void simpleAlertTestCase() { + Reporter.log("simpleAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("simple")).click(); + Reporter.log("Simple Alert opened |"); + + // Switch to alert window + Alert simpleAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = simpleAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("You've just triggered a simple alert!", alertText); + + simpleAlert.accept(); + Reporter.log("Alert closed"); + + Reporter.log("Test case ended |"); + } + + @Test(priority = 2) + public void confirmAlertTestCase() { + Reporter.log("confirmAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("confirmation")).click(); + Reporter.log("Confirm Alert opened |"); + + // Switch to alert window + Alert confirmAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = confirmAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("You've just triggered a confirmation alert!", alertText); + + confirmAlert.accept(); + Reporter.log("Alert closed |"); + + Reporter.log("Test case ended |"); + } + + @Test(priority = 3) + public void promptAlertTestCase() { + Reporter.log("promptAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("prompt")).click(); + Reporter.log("Prompt Alert opened |"); + + // Switch to alert window + Alert promptAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = promptAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("I'm a Prompt! Type something into me!", alertText); + // Type some text into the prompt + promptAlert.sendKeys("Awesome!"); + Reporter.log("Text entered in prompt alert |"); + // Close the prompt + promptAlert.accept(); + Reporter.log("Alert closed |"); + + Reporter.log("Test case ended |"); + } + + @AfterClass + public void tearDown() { + Reporter.log("Ending Test |"); + // Close the driver + driver.close(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/testing.xml b/TestNG/Activities/testing.xml new file mode 100644 index 0000000000..5fa68145cd --- /dev/null +++ b/TestNG/Activities/testing.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + From 0615bb3365b983eabc7a55eae28d8255f980e06c Mon Sep 17 00:00:00 2001 From: aasashi <162731783+aasashi@users.noreply.github.com> Date: Wed, 19 Feb 2025 06:50:52 +0530 Subject: [PATCH 6/6] Uploaded Python Activities --- Python/Activities/Activity1.py | 8 +++ Python/Activities/Activity10.py | 14 +++++ Python/Activities/Activity11.py | 18 ++++++ Python/Activities/Activity12.py | 21 +++++++ Python/Activities/Activity13.py | 23 ++++++++ Python/Activities/Activity14.py | 27 +++++++++ Python/Activities/Activity15.py | 4 ++ Python/Activities/Activity16.py | 24 ++++++++ Python/Activities/Activity17_18.py | 44 ++++++++++++++ Python/Activities/Activity19_20.py | 55 +++++++++++++++++ Python/Activities/Activity2.py | 6 ++ Python/Activities/Activity21_22_test.py | 60 +++++++++++++++++++ Python/Activities/Activity23_test.py | 16 +++++ Python/Activities/Activity24_test.py | 14 +++++ Python/Activities/Activity3.py | 45 ++++++++++++++ Python/Activities/Activity4.py | 78 +++++++++++++++++++++++++ Python/Activities/Activity5.py | 7 +++ Python/Activities/Activity6.py | 3 + Python/Activities/Activity7.py | 8 +++ Python/Activities/Activity8.py | 16 +++++ Python/Activities/Activity9.py | 34 +++++++++++ Python/Activities/conftest.py | 19 ++++++ Python/Activities/first_test.py | 12 ++++ 23 files changed, 556 insertions(+) create mode 100644 Python/Activities/Activity1.py create mode 100644 Python/Activities/Activity10.py create mode 100644 Python/Activities/Activity11.py create mode 100644 Python/Activities/Activity12.py create mode 100644 Python/Activities/Activity13.py create mode 100644 Python/Activities/Activity14.py create mode 100644 Python/Activities/Activity15.py create mode 100644 Python/Activities/Activity16.py create mode 100644 Python/Activities/Activity17_18.py create mode 100644 Python/Activities/Activity19_20.py create mode 100644 Python/Activities/Activity2.py create mode 100644 Python/Activities/Activity21_22_test.py create mode 100644 Python/Activities/Activity23_test.py create mode 100644 Python/Activities/Activity24_test.py create mode 100644 Python/Activities/Activity3.py create mode 100644 Python/Activities/Activity4.py create mode 100644 Python/Activities/Activity5.py create mode 100644 Python/Activities/Activity6.py create mode 100644 Python/Activities/Activity7.py create mode 100644 Python/Activities/Activity8.py create mode 100644 Python/Activities/Activity9.py create mode 100644 Python/Activities/conftest.py create mode 100644 Python/Activities/first_test.py diff --git a/Python/Activities/Activity1.py b/Python/Activities/Activity1.py new file mode 100644 index 0000000000..d0e5427b16 --- /dev/null +++ b/Python/Activities/Activity1.py @@ -0,0 +1,8 @@ + +#Write a program that asks the user to enter their name and their age. +name = input("Enter your name :") +age = int (input("Enter your age :")) + +#Print out a message addressed to them that tells them the year that they will turn 100 years old. +result =name + ", you will turn 100 in {}".format((2025-age) + 100) +print(result) \ No newline at end of file diff --git a/Python/Activities/Activity10.py b/Python/Activities/Activity10.py new file mode 100644 index 0000000000..5ef5382b51 --- /dev/null +++ b/Python/Activities/Activity10.py @@ -0,0 +1,14 @@ + +# Given tuple + +num_tuple = tuple(input("Enter a sequence of comma separated values: ").split(",")) + +print("Given list is ", num_tuple) + +# Print elements that are divisible by 5 + +print("Elements that are divisible by 5:") + +for num in num_tuple: + if (int(num) % 5 == 0): + print(num) \ No newline at end of file diff --git a/Python/Activities/Activity11.py b/Python/Activities/Activity11.py new file mode 100644 index 0000000000..a63dea8055 --- /dev/null +++ b/Python/Activities/Activity11.py @@ -0,0 +1,18 @@ + +fruit_shop = { + "pineapple": 60, + "banana": 65, + "orange": 70, + "guava": 55 +} + + +search_term = input("What are you looking for?: ").lower() + +if(search_term in fruit_shop): + + print(search_term + " costs " + str(fruit_shop[search_term]) + " rupees") + +else: + + print("Fruits out of stock") \ No newline at end of file diff --git a/Python/Activities/Activity12.py b/Python/Activities/Activity12.py new file mode 100644 index 0000000000..907986ab54 --- /dev/null +++ b/Python/Activities/Activity12.py @@ -0,0 +1,21 @@ +# Define function to calculate sum + +def calculateSum(num): + + if num: + + # Recursive function call + + return num + calculateSum(num-1) + + else: + + return 0 + +# Call calculateSum() function + +res = calculateSum(10) + +# Print result + +print(res) \ No newline at end of file diff --git a/Python/Activities/Activity13.py b/Python/Activities/Activity13.py new file mode 100644 index 0000000000..05aec3cbdd --- /dev/null +++ b/Python/Activities/Activity13.py @@ -0,0 +1,23 @@ + +# Custom function to calculate sum +def calculate_sum(numbers): + + sum = 0 + + for number in numbers: + + sum += int(number) + + return sum + +# Define the list of numbers + +#numList = [10, 40, 60, 90] +numList =list(input("Enter a sequence of comma separated values: ").split(",")) +# Call the sum() function with numList as argument + +result = calculate_sum(numList) + +# Print result with message + +print("The sum of all the elements is: " + str(result)) \ No newline at end of file diff --git a/Python/Activities/Activity14.py b/Python/Activities/Activity14.py new file mode 100644 index 0000000000..9f5a301edb --- /dev/null +++ b/Python/Activities/Activity14.py @@ -0,0 +1,27 @@ +def fibonacci(number): + + if number <= 1: + + return number + + else: + + return(fibonacci(number-1) + fibonacci(number-2)) + + + +nterms = int(input("Enter a number: ")) + + + +if nterms <= 0: + + print("Please enter a positive number") + +else: + + print("Fibonacci Sequence: ") + + for i in range(nterms): + + print(fibonacci(i)) \ No newline at end of file diff --git a/Python/Activities/Activity15.py b/Python/Activities/Activity15.py new file mode 100644 index 0000000000..6fa890a4fe --- /dev/null +++ b/Python/Activities/Activity15.py @@ -0,0 +1,4 @@ +try: + print(x) +except NameError: + print("x hasn't been defined yet.") \ No newline at end of file diff --git a/Python/Activities/Activity16.py b/Python/Activities/Activity16.py new file mode 100644 index 0000000000..f375e530ed --- /dev/null +++ b/Python/Activities/Activity16.py @@ -0,0 +1,24 @@ + +class Car: + 'This class is for activity16' + def __init__(self, manufacturer, model, make, transmission, color): + + self.manufacturer = manufacturer + self.model = model + self.make = make + self.transmission = transmission + self.color = color + + def accelerate(self): + print(self.manufacturer + " " + self.model + " has started moving") + + + def stop(self): + print(self.manufacturer + " " + self.model + " has stopped moving") + +car1 = Car("Toyota", "Corolla", "2015", "Manual", "White") +car2 = Car("Maruti", "800", "2013", "Manual", "Red") +car3 = Car("Suzuki", "Swift", "2017", "Automatic", "Black") + +car3.accelerate() +car3.stop() \ No newline at end of file diff --git a/Python/Activities/Activity17_18.py b/Python/Activities/Activity17_18.py new file mode 100644 index 0000000000..769251a15e --- /dev/null +++ b/Python/Activities/Activity17_18.py @@ -0,0 +1,44 @@ +# Import pandas +import pandas +# Create a Dictionary that will hold our data +data = { + "Usernames": ["admin", "charles", "deku"], + "Passwords": ["password", "Charl13", "AllMight"] +} +# Create a DataFrame using that data +dataframe = pandas.DataFrame(data) + +dataframe.to_csv("Activities/outputs/sample.csv", index=False) + +#Activity 18: +# Read the CSV file and store it into a DataFrame + +dataframe = pandas.read_csv("Activities/outputs/sample.csv") + +# Print the full data + +print("Full Data: ") +print(dataframe) + +# Print the values in the Usernames column only +print("===============") +print("Usernames:") +print(dataframe["Usernames"]) + + +# Print the username and password of the second row + +print("===============") +print("Username: ", dataframe["Usernames"][1], " | ", "Password: ", dataframe["Passwords"][1]) + +#Sort the Usernames column in ascending order + +print("====================================") +print("Data sorted in ascending Usernames:") +print(dataframe.sort_values('Usernames')) + + +#Sort the Passwords column in descending order +print("====================================") +print("Data sorted in descending Passwords:") +print(dataframe.sort_values('Passwords', ascending=False)) \ No newline at end of file diff --git a/Python/Activities/Activity19_20.py b/Python/Activities/Activity19_20.py new file mode 100644 index 0000000000..aadae25734 --- /dev/null +++ b/Python/Activities/Activity19_20.py @@ -0,0 +1,55 @@ +# Import pandas +import pandas +from pandas import ExcelWriter +# Create a dictionary that will be used to create the DataFrame + +data = { + + 'FirstName':["Satvik", "Avinash", "Lahri"], + + 'LastName':["Shah", "Kati", "Rath"], + + 'Email':["satshah@example.com", "avinashK@example.com", "lahri.rath@example.com"], + + 'PhoneNumber':["4537829158", "4892184058", "4528727830"] + +} +# Create the DataFrame that will be written to the excel file + +dataframe = pandas.DataFrame(data) +# Print the dataframe + +print(dataframe) +# Write the dataframe to a Excel file +writer = ExcelWriter('Activities/outputs/sample1.xlsx') +dataframe.to_excel(excel_writer=writer, sheet_name='Sheet1', index = False) +# Commit data to the Excel file +writer.close() + + +#Activity 20: +# Read data from Excel sheet + +dataframe = pandas.read_excel('Activities/outputs/sample1.xlsx') + +# Print the number of rows and columns + +print("====================================") +# Print the number of rows and columns +print("-----------------------") +print("Shape of DataFrame: ", dataframe.shape) +print("No. of rows:", dataframe.shape[0]) +print("No. of columns:", dataframe.shape[1]) +print("Number of rows and columns:", dataframe.shape) + +# Print the data in the emails column only + +print("====================================") + +print("Emails:") +print(dataframe['Email']) +# Sort the data based on FirstName in ascending order and print the data + +print("====================================") +print("Sorted data:") +print(dataframe.sort_values('FirstName')) \ No newline at end of file diff --git a/Python/Activities/Activity2.py b/Python/Activities/Activity2.py new file mode 100644 index 0000000000..9d13722bc5 --- /dev/null +++ b/Python/Activities/Activity2.py @@ -0,0 +1,6 @@ +inputNum = int(input("Enter a number:")) + +if (inputNum % 2) ==0: + print(inputNum, "is an even number") +else: + print(str(inputNum) + "is an odd number") \ No newline at end of file diff --git a/Python/Activities/Activity21_22_test.py b/Python/Activities/Activity21_22_test.py new file mode 100644 index 0000000000..f25b2d0a3b --- /dev/null +++ b/Python/Activities/Activity21_22_test.py @@ -0,0 +1,60 @@ + +import pytest +# Additon test + +def test_addition(): + # Initialize two numbers + + num1 = 10 + + num2 = 15 + # Add them + + sum = num1 + num2 + # Assertion + + assert sum == 25 +# Subtraction test + +def test_subtraction(): + # Initialize two numbers + + num1 = 50 + + num2 = 35 + + # Subtract them + diff = num1 - num2 + # Assertion + + assert diff == 15 + +# Multiplication test + +@pytest.mark.activity_22 +def test_multiplication(): + + # Initialize two numbers + + num1 = 5 + + num2 = 20 + # Multiply them + + prod = num1 * num2 + # Assertion + + assert prod == 100 + +# Division test + +@pytest.mark.activity_22 +def test_division(): + # Initialize two numbers + num1 = 100 + + num2 = 5 + # Divide them + quot = num1 / num2 + # Assertion + assert quot == 20 \ No newline at end of file diff --git a/Python/Activities/Activity23_test.py b/Python/Activities/Activity23_test.py new file mode 100644 index 0000000000..81dfe82a92 --- /dev/null +++ b/Python/Activities/Activity23_test.py @@ -0,0 +1,16 @@ +import pytest +# Create fixture +@pytest.fixture + +def num_list(): + int_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + return int_list + +def test_sum(num_list): + + sum = 0 + for n in num_list: + + sum += n + assert sum == 55 \ No newline at end of file diff --git a/Python/Activities/Activity24_test.py b/Python/Activities/Activity24_test.py new file mode 100644 index 0000000000..160865827f --- /dev/null +++ b/Python/Activities/Activity24_test.py @@ -0,0 +1,14 @@ +import pytest + +# Set up the paremeterized test method +@pytest.mark.parametrize("earned, spent, expected", [ (30, 10, 20), (20, 2, 18), ]) +def test_transactions(wallet_amount, earned, spent, expected): + + # Add money to your wallet + wallet_amount += earned + + # Subtract amount from wallet + wallet_amount -= spent + + # Assertion + assert wallet_amount == expected \ No newline at end of file diff --git a/Python/Activities/Activity3.py b/Python/Activities/Activity3.py new file mode 100644 index 0000000000..57db5091b2 --- /dev/null +++ b/Python/Activities/Activity3.py @@ -0,0 +1,45 @@ + +user1_answer = input(user1 + ", do you want to choose rock, paper or scissors? ").lower() +user2_answer = input(user2 + ", do you want to choose rock, paper or scissors? ").lower() + + + +# Run the algorithm to see who wins + +if user1_answer == user2_answer: + + print("It's a tie!") + +elif user1_answer == 'rock': + + if user2_answer == 'scissors': + + print("Rock wins!") + + else: + + print("Paper wins!") + +elif user1_answer == 'scissors': + + if user2_answer == 'paper': + + print("Scissors win!") + + else: + + print("Rock wins!") + +elif user1_answer == 'paper': + + if user2_answer == 'rock': + + print("Paper wins!") + + else: + + print("Scissors win!") + +else: + + print("Invalid input! You have not entered rock, paper or scissors, try again.") \ No newline at end of file diff --git a/Python/Activities/Activity4.py b/Python/Activities/Activity4.py new file mode 100644 index 0000000000..a16585e922 --- /dev/null +++ b/Python/Activities/Activity4.py @@ -0,0 +1,78 @@ + +user1 = input("What is Player 1's name? ") +user2 = input("What is Player 2's name? ") +while True: + + # Ask User1's choice + user1_answer = input(user1 + ", do you want to choose rock, paper or scissors? ").lower() + # Ask User2's choice + user2_answer = input(user2 + ", do you want to choose rock, paper or scissors? ").lower() + + + + # Run the algorithm to see who wins + + if user1_answer == user2_answer: + + print("It's a tie!") + + elif user1_answer == 'rock': + + if user2_answer == 'scissors': + + print("Rock wins!") + + else: + + print("Paper wins!") + + elif user1_answer == 'scissors': + + if user2_answer == 'paper': + + print("Scissors win!") + + else: + + print("Rock wins!") + + elif user1_answer == 'paper': + + if user2_answer == 'rock': + + print("Paper wins!") + + else: + + print("Scissors win!") + + else: + + print("Invalid input! You have not entered rock, paper or scissors, try again.") + + # Ask them if they want to play again + repeat = input("Do you want to play another round? Yes/No: ").lower() + + # If they say yes, don't do anything + + if(repeat == "yes"): + + pass + + # If they say no, exit the game + + elif(repeat == "no"): + + break + + # If they say anything else, exit with an error message. + + else: + + print("You entered an invalid option. Exiting now.") + + raise SystemExit + + print("Another around starting") + +print("End of game") \ No newline at end of file diff --git a/Python/Activities/Activity5.py b/Python/Activities/Activity5.py new file mode 100644 index 0000000000..5b9f1e718e --- /dev/null +++ b/Python/Activities/Activity5.py @@ -0,0 +1,7 @@ +#Multiplication Tables +number = int(input("Input a number: ")) +# use for loop to iterate 10 times + +for i in range(1,11): + + print(number, ' x ', i, ' = ', number*i) \ No newline at end of file diff --git a/Python/Activities/Activity6.py b/Python/Activities/Activity6.py new file mode 100644 index 0000000000..10d298c76c --- /dev/null +++ b/Python/Activities/Activity6.py @@ -0,0 +1,3 @@ +#Pattern Generator +for i in range(10): + print(str(i) * i) \ No newline at end of file diff --git a/Python/Activities/Activity7.py b/Python/Activities/Activity7.py new file mode 100644 index 0000000000..48c1af5cc5 --- /dev/null +++ b/Python/Activities/Activity7.py @@ -0,0 +1,8 @@ + #List Sum Calculator + +num_list= [10,25,55] +sum = 0 + +for number in num_list: + sum += number +print(sum) \ No newline at end of file diff --git a/Python/Activities/Activity8.py b/Python/Activities/Activity8.py new file mode 100644 index 0000000000..02c7190a9c --- /dev/null +++ b/Python/Activities/Activity8.py @@ -0,0 +1,16 @@ +# Given list of numbers +num_list= list(input("Enter a sequence of comma separated values: ").split(",")) + +print("Given list is ", num_list) + +# Get first element in list +firstElement = num_list[0] +# Get last element in list +lastElement = num_list[-1] +# Check if first and last element are equal + +if (firstElement == lastElement): + print("The values are same") +else: + print("The values are not same") + diff --git a/Python/Activities/Activity9.py b/Python/Activities/Activity9.py new file mode 100644 index 0000000000..66018de7eb --- /dev/null +++ b/Python/Activities/Activity9.py @@ -0,0 +1,34 @@ + +# Given lists +listOne = [10, 20, 23, 11, 17] +listTwo = [13, 43, 24, 36, 12] + +# Print the lists + +print("First List ", listOne) +print("Second List ", listTwo) + +# Declare a third list that will contain the result + +thirdList = [] + +# Iterate through first list to get odd elements + +for num in listOne: + + if (num % 2 != 0): + + thirdList.append(num) + +# Iterate through first list to get even elements + +for num in listTwo: + + if (num % 2 == 0): + + thirdList.append(num) + +# Print result + +print("result List is:") +print(thirdList) \ No newline at end of file diff --git a/Python/Activities/conftest.py b/Python/Activities/conftest.py new file mode 100644 index 0000000000..44abd9c14b --- /dev/null +++ b/Python/Activities/conftest.py @@ -0,0 +1,19 @@ + +import pytest +# Create fixture + +@pytest.fixture +def num_list(): + # Create list + list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + # Alternatively + # list = list(range(11) + + return list + + +@pytest.fixture +def wallet_amount(): + amount = 0 + return amount \ No newline at end of file diff --git a/Python/Activities/first_test.py b/Python/Activities/first_test.py new file mode 100644 index 0000000000..fc15c5373e --- /dev/null +++ b/Python/Activities/first_test.py @@ -0,0 +1,12 @@ +import pytest +import math +def test_sqrt(): + num = 25 + assert math.sqrt(num) == 5 + +def testsquare(): + num = 7 + assert num*num == 40 + +def testquality(): + assert 10 == 11 \ No newline at end of file