diff --git a/Cucumber/Activities/Activity2.feature b/Cucumber/Activities/Activity2.feature new file mode 100644 index 0000000000..205e391c6b --- /dev/null +++ b/Cucumber/Activities/Activity2.feature @@ -0,0 +1,8 @@ +@activity2 +Feature: Activity to test the login feature + + Scenario: Successful login + Given the user is on the login page + When the user enters username and password + And clicks the submit button + Then get the confirmation message and verify it \ No newline at end of file diff --git a/Cucumber/Activities/Activity3.feature b/Cucumber/Activities/Activity3.feature new file mode 100644 index 0000000000..8092cffc31 --- /dev/null +++ b/Cucumber/Activities/Activity3.feature @@ -0,0 +1,40 @@ +@activity3 +Feature: Testing with Tags + @SimpleAlert @SmokeTest + Scenario: Test for Simple Alert + Given User is on the page + When User clicks the Simple Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert + And Read the result text + @ConfirmAlert + Scenario: Test for Confirm Alert + Given User is on the page + When User clicks the Confirmation Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert with Cancel + And Read the result text + @PromptAlert + Scenario: Test for Prompt Alert + Given User is on the page + When User clicks the Prompt Alert button + Then Alert opens + And Read the text from it and print it + And Write a custom message in it + And Close the alert + And Read the result text + # An alternate approach using Scenario outline + Scenario Outline: + Given User is on the page + When User clicks the Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert + And Read the result text + Examples: + | Type | + | Simple | + | Confirmation | + | Prompt | \ No newline at end of file diff --git a/Cucumber/Activities/Activity4.feature b/Cucumber/Activities/Activity4.feature new file mode 100644 index 0000000000..2629ca5dfd --- /dev/null +++ b/Cucumber/Activities/Activity4.feature @@ -0,0 +1,8 @@ +@activity4 +Feature: Data driven test without Examples + + Scenario: Testing with correct data from inputs + Given the user is on the login page + When the user enters "admin" and "password" + And clicks the submit button + Then get the confirmation text and verify message as "Welcome Back, admin" \ No newline at end of file diff --git a/Cucumber/Activities/Activity5.feature b/Cucumber/Activities/Activity5.feature new file mode 100644 index 0000000000..30a59b3f8e --- /dev/null +++ b/Cucumber/Activities/Activity5.feature @@ -0,0 +1,11 @@ +@Activity5 +Feature: Data driven test without Examples + Scenario Outline: Testing with data from scenario + Given the user is on the login page + When the user enters "" and "" + And clicks the submit button + Then get the confirmation text and verify message as "" + Examples: + | Usernames | Passwords | Message | + | admin | password | Welcome Back, Admin! | + | admin | WrongPassword | Invalid credentials | \ No newline at end of file diff --git a/Cucumber/Activities/Activity6.feature b/Cucumber/Activities/Activity6.feature new file mode 100644 index 0000000000..2ef89199c4 --- /dev/null +++ b/Cucumber/Activities/Activity6.feature @@ -0,0 +1,9 @@ +@Activity6 +Feature: To test input with Datatables +Scenario: Adding items to a to-do list + Given user is on the To-Do list page + When user adds the following task + | task1 | + | task2 | + | task3 | + Then they can see the task added to the list \ No newline at end of file diff --git a/Cucumber/Activities/AlertTestSteps.java b/Cucumber/Activities/AlertTestSteps.java new file mode 100644 index 0000000000..0f804eb02c --- /dev/null +++ b/Cucumber/Activities/AlertTestSteps.java @@ -0,0 +1,53 @@ +package stepDefinitions; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +public class AlertTestSteps extends BaseClass { + Alert alert; + @Given("User is on the page") + public void openPage() { + // Open browser + driver.get("https://training-support.net/webelements/alerts"); + } + @When("User clicks the Simple Alert button") + public void openSimpleAlert() { + driver.findElement(By.id("simple")).click(); + } + @When("User clicks the Confirmation Alert button") + public void openConfirmAlert() { + driver.findElement(By.id("confirmation")).click(); + } + @When("User clicks the Prompt Alert button") + public void openPromptAlert() { + driver.findElement(By.id("prompt")).click(); + } + @Then("Alert opens") + public void switchFocus() { + alert = driver.switchTo().alert(); + } + @And("Read the text from it and print it") + public void readAlert() { + System.out.println("Alert says: " + alert.getText()); + } + @And("Write a custom message in it") + public void writeToPrompt() { + alert.sendKeys("Custom Message"); + } + @And("Close the alert") + public void closeAlert() { + alert.accept(); + } + @And("Close the alert with Cancel") + public void closeAlertWithCAncel() { + alert.dismiss(); + } + @And("Read the result text") + public void readResultText() { + String message = driver.findElement(By.id("result")).getText(); + System.out.println("Action performed: " + message); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/BaseClass.java b/Cucumber/Activities/BaseClass.java new file mode 100644 index 0000000000..5f6cc1bd0f --- /dev/null +++ b/Cucumber/Activities/BaseClass.java @@ -0,0 +1,11 @@ +package stepDefinitions; + + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BaseClass { + static WebDriver driver; + static WebDriverWait wait; + +} diff --git a/Cucumber/Activities/DataTableExampleSteps.java b/Cucumber/Activities/DataTableExampleSteps.java new file mode 100644 index 0000000000..09bb999d24 --- /dev/null +++ b/Cucumber/Activities/DataTableExampleSteps.java @@ -0,0 +1,30 @@ +package stepDefinitions; + +import java.util.List; +import io.cucumber.datatable.DataTable; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.openqa.selenium.By; +import static org.junit.jupiter.api.Assertions.assertEquals; +public class DataTableExampleSteps extends BaseClass { + @Given("user is on the To-Do list page") + public void OpenPage() { + driver.get("https://training-support.net/webelements/todo-list"); + assertEquals(driver.getTitle(), "Selenium: To-Do List"); +} + @When("user adds the following task") + public void inputTasks(DataTable inputTasks) throws InterruptedException { + List tasks = inputTasks.asList(); + System.out.println(tasks); + for(String task : tasks) { + driver.findElement(By.id("todo-input")).sendKeys(task); + driver.findElement(By.id("todo-add")).click(); + Thread.sleep(2000); + } + } + @Then("they can see the task added to the list") + public void verifyResults() { + System.out.println("All tasks present"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/FirstTest.feature b/Cucumber/Activities/FirstTest.feature new file mode 100644 index 0000000000..8962690641 --- /dev/null +++ b/Cucumber/Activities/FirstTest.feature @@ -0,0 +1,6 @@ +@activity1 +Feature: Basic Syntax +Scenario: Opening a webpage using Selenium + Given the user is on the TS home page + When they click on the About Us link + Then They are the redirected to the About page \ No newline at end of file diff --git a/Cucumber/Activities/FirstTest.java b/Cucumber/Activities/FirstTest.java new file mode 100644 index 0000000000..32167fa509 --- /dev/null +++ b/Cucumber/Activities/FirstTest.java @@ -0,0 +1,25 @@ +package stepDefinitions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.openqa.selenium.By; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +public class FirstTest extends BaseClass { + @Given("the user is on the TS home page") + public void openPage() { + // Open the TS home page + driver.get("https://training-support.net"); + // Assertion + assertEquals(driver.getTitle(), "Training Support"); + } + @When("they click on the About Us link") + public void clickLink() { + // Find and click the About Us link + driver.findElement(By.linkText("About Us")).click(); + } + @Then("They are the redirected to the About page") + public void redirectToAbout() { + // Get the new page title and assert + assertEquals(driver.getTitle(), "About Training Support"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/Fixture.java b/Cucumber/Activities/Fixture.java new file mode 100644 index 0000000000..bfc9bca805 --- /dev/null +++ b/Cucumber/Activities/Fixture.java @@ -0,0 +1,21 @@ +package stepDefinitions; + +import java.time.Duration; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import io.cucumber.java.AfterAll; +import io.cucumber.java.BeforeAll; +public class Fixture extends BaseClass { + @BeforeAll + public static void setUp() { + // Initialize Firefox Driver + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + @AfterAll + public static void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/LoginSteps.java b/Cucumber/Activities/LoginSteps.java new file mode 100644 index 0000000000..543351a5cb --- /dev/null +++ b/Cucumber/Activities/LoginSteps.java @@ -0,0 +1,70 @@ +package stepDefinitions; + +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class LoginSteps extends BaseClass { + @Given("the user is on the login page") + public void openPage() { + // Open the login page + driver.get("https://training-support.net/webelements/login-form"); + // Assert page title + assertEquals("Selenium: Login Form", driver.getTitle()); + } + @When("the user enters username and password") + public void enterCredentials() { + // Find username field and enter username + driver.findElement(By.id("username")).sendKeys("admin"); + // Find password field and enter password + driver.findElement(By.id("password")).sendKeys("password"); + // To get the entered values + String enteredUsername = driver.findElement(By.id("username")).getAttribute("value"); + // System.out.println("Username field has " + enteredUsername); + assertEquals(enteredUsername, "admin"); + } + @When("the user enters {string} and {string}") + public void enterCredentialswithparams(String username,String password) { + // Find username field and enter username + driver.findElement(By.id("username")).sendKeys(username); + // Find password field and enter password + driver.findElement(By.id("password")).sendKeys(password); + // To get the entered values + String enteredUsername = driver.findElement(By.id("username")).getAttribute("value"); + System.out.println("Username field has " + enteredUsername); + assertEquals(enteredUsername, "admin"); + } +// } + @And("clicks the submit button") + public void clickSubmit() { + // Find the submit button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + } + @Then("get the confirmation message and verify it") + public void getMessage() { + String message = driver.findElement(By.tagName("h1")).getText(); + assertEquals("Login Success!", message); + } + +@Then("get the confirmation text and verify message as {string}") + public void confirmMessageAsInput(String expectedMessage) { + // Find the confirmation message + String message = "NOT FOUND"; + if (expectedMessage.contains("Invalid")) { + message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("h2#subheading"))) + .getText(); + } + else { + message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("h2.mt-5"))) + .getText(); + } + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h2.mt-5"),"Welcome")); + String message1 = driver.findElement(By.cssSelector("h2.mt-5")).getText(); + // Assert message + assertEquals(expectedMessage, message1); +} +} \ No newline at end of file diff --git a/Cucumber/Activities/TestRunner.java b/Cucumber/Activities/TestRunner.java new file mode 100644 index 0000000000..e6fbba2334 --- /dev/null +++ b/Cucumber/Activities/TestRunner.java @@ -0,0 +1,28 @@ +package TestRunner; + +import org.junit.platform.suite.api.Suite; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.SelectClasspathResource; +import io.cucumber.junit.platform.engine.Constants; +@Suite +@IncludeEngines("cucumber") +@SelectClasspathResource("Features")//path of feature +@ConfigurationParameter( + key = Constants.GLUE_PROPERTY_NAME, + value = "stepDefinitions") +@ConfigurationParameter( + key = Constants.FILTER_TAGS_PROPERTY_NAME, + value = "@activity2") +//@ConfigurationParameter( + // key = Constants.PLUGIN_PROPERTY_NAME, + // value = "pretty, html:Reports/HTML_Report.html, junit:Reports/XML_Report.xml, json:Reports/JSON_Report.json" + //) +public class TestRunner { + +} + + + + + diff --git a/Java/Activities/Activity1.java b/Java/Activities/Activity1.java new file mode 100644 index 0000000000..d4490c3702 --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,15 @@ +package Activity; + +public class Activity1 { + + public static void main(String[] args) { + Car carobj = new Car(); + carobj.make = 2020; + carobj.color = "Black"; + carobj.transmission = "Manual"; + //Using Car class method + carobj.displayCharacterstics(); + carobj.accelerate(); + carobj.brake(); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity10.java b/Java/Activities/Activity10.java new file mode 100644 index 0000000000..f989c58182 --- /dev/null +++ b/Java/Activities/Activity10.java @@ -0,0 +1,32 @@ +package Activity; + +import java.util.HashSet; + +public class Activity10 { + public static void main(String[] args) { + HashSet hs = new HashSet(); + + hs.add("M"); + hs.add("B"); + hs.add("C"); + hs.add("A"); + hs.add("M"); + hs.add("X"); + + System.out.println("Original HashSet: " + hs); + + System.out.println("Size of HashSet: " + hs.size()); + + System.out.println("Removing A from HashSet: " + hs.remove("A")); + + if(hs.remove("Z")) { + System.out.println("Z removed from the Set"); + } else { + System.out.println("Z is not present in the Set"); + } + + System.out.println("Checking if M is present: " + hs.contains("M")); + + System.out.println("Updated HashSet: " + hs); + } +} diff --git a/Java/Activities/Activity11.java b/Java/Activities/Activity11.java new file mode 100644 index 0000000000..737779a41c --- /dev/null +++ b/Java/Activities/Activity11.java @@ -0,0 +1,27 @@ +package Activity; + +import java.util.HashMap; + +public class Activity11 { + public static void main(String[] args) { + HashMap hash_map = new HashMap(); + hash_map.put(1, "Red"); + hash_map.put(2, "Green"); + hash_map.put(3, "Blue"); + hash_map.put(4, "White"); + hash_map.put(5, "Black"); + + System.out.println("The Original map: " + hash_map); + + hash_map.remove(4); + System.out.println("After removing White: " + hash_map); + + if(hash_map.containsValue("Green")) { + System.out.println("Green exists in the Map"); + } else { + System.out.println("Green does not exist in the Map"); + } + + System.out.println("Number of pairs in the Map is: " + hash_map.size()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity12.java b/Java/Activities/Activity12.java new file mode 100644 index 0000000000..cf0078cc56 --- /dev/null +++ b/Java/Activities/Activity12.java @@ -0,0 +1,20 @@ +package Activity; + + +interface Addable { + int add(int a, int b); +} + +public class Activity12 { + public static void main(String[] args) { + + Addable ad1 = (a, b) -> (a + b); + + Addable ad2 = (int a, int b) -> { + return (a + b); + }; + + System.out.println(ad1.add(10, 20)); + System.out.println(ad2.add(100, 200)); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity13.java b/Java/Activities/Activity13.java new file mode 100644 index 0000000000..9d92f34350 --- /dev/null +++ b/Java/Activities/Activity13.java @@ -0,0 +1,26 @@ +package Activity; + +import java.util.*; + +public class Activity13 { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + ArrayList list = new ArrayList(); + Random indexGen = new Random(); + + System.out.print("Enter integers please "); + System.out.println("(EOF or non-integer to terminate): "); + + while(scan.hasNextInt()) { + list.add(scan.nextInt()); + } + + Integer nums[] = list.toArray(new Integer[0]); + int index = indexGen.nextInt(nums.length); + System.out.println("Index value generated: " + index); + System.out.println("Value in arary at generated index: " + nums[index]); + + scan.close(); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity14.java b/Java/Activities/Activity14.java new file mode 100644 index 0000000000..bcd507526f --- /dev/null +++ b/Java/Activities/Activity14.java @@ -0,0 +1,35 @@ +package Activity; + +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/Activity/Newfile.txt"); + boolean fStatus = file.createNewFile(); + if(fStatus) { + System.out.println("File created successfully!"); + } else { + System.out.println("File already exists at this path."); + } + + File fileUtil = FileUtils.getFile("src/Activity/Newfile.txt"); + + System.out.println("Data in file: " + FileUtils.readFileToString(fileUtil, "UTF8")); + + File destDir = new File("resources"); + + FileUtils.copyFileToDirectory(file, destDir); + + File newFile = FileUtils.getFile(destDir, "newfile.txt"); + + String newFileData = FileUtils.readFileToString(newFile, "UTF8"); + + 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..d43dcec237 --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,32 @@ +package Activity; + +import java.util.*; + +public class Activity2 { + public static void main(String[] args) { + int[] numArr = {10, 77, 10, 54, -11, 10}; + System.out.println("Original Array: " + Arrays.toString(numArr)); + + int searchNum = 10; + int fixedSum = 30; + + System.out.println("Result: " + result(numArr, searchNum, fixedSum)); + } + + public static boolean result(int[] numbers, int searchNum, int fixedSum) { + int temp_sum = 0; + for (int number : numbers) { + + if (number == searchNum) { + + temp_sum += searchNum; + } + + if (temp_sum > fixedSum) { + break; + } + } + + return temp_sum == fixedSum; + } +} \ No newline at end of file diff --git a/Java/Activities/Activity3.java b/Java/Activities/Activity3.java new file mode 100644 index 0000000000..64261b7326 --- /dev/null +++ b/Java/Activities/Activity3.java @@ -0,0 +1,25 @@ +package Activity; + +class Activity3 { + public static void main(String args[]) { + double seconds = 1000000000; + + double EarthSeconds = 31557600; + double MercurySeconds = 0.2408467; + double VenusSeconds = 0.61519726; + double MarsSeconds = 1.8808158; + double JupiterSeconds = 11.862615; + double SaturnSeconds = 29.447498; + double UranusSeconds = 84.016846; + double NeptuneSeconds = 164.79132; + + System.out.println("Age on Mercury: " + seconds / EarthSeconds / MercurySeconds); + System.out.println("Age on Venus: " + seconds / EarthSeconds / VenusSeconds); + System.out.println("Age on Earth: " + seconds / EarthSeconds); + System.out.println("Age on Mars: " + seconds / EarthSeconds / MarsSeconds); + System.out.println("Age on Jupiter: " + seconds / EarthSeconds / JupiterSeconds); + System.out.println("Age on Saturn: " + seconds / EarthSeconds / SaturnSeconds); + System.out.println("Age on Uranus: " + seconds / EarthSeconds / UranusSeconds); + System.out.println("Age on Neptune: " + seconds / EarthSeconds / NeptuneSeconds); + } +} diff --git a/Java/Activities/Activity4.java b/Java/Activities/Activity4.java new file mode 100644 index 0000000000..b4eeec2f01 --- /dev/null +++ b/Java/Activities/Activity4.java @@ -0,0 +1,27 @@ +package Activity; + +import java.util.Arrays; + +class Activity4 { + static void ascendingSort(int array[]) { + int size = array.length, i; + + for (i = 1; i < size; i++) { + int key = array[i]; + int j = i - 1; + + while (j >= 0 && key < array[j]) { + array[j + 1] = array[j]; + --j; + } + array[j + 1] = key; + } + } + + public static void main(String args[]) { + int[] data = { 9, 5, 1, 4, 3 }; + ascendingSort(data); + System.out.println("Sorted Array in Ascending Order: "); + System.out.println(Arrays.toString(data)); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity5.java b/Java/Activities/Activity5.java new file mode 100644 index 0000000000..28ee04bc8d --- /dev/null +++ b/Java/Activities/Activity5.java @@ -0,0 +1,27 @@ +package Activity; + +abstract class Book { + String title; + abstract void setTitle(String s); + + String getTitle() { + return title; + } +} + +class MyBook extends Book { + public void setTitle(String s) { + title = s; + } +} + +public class Activity5 { + + public static void main(String []args) { + String title = "Hover Car Racer"; + Book newNovel = new MyBook(); + newNovel.setTitle(title); + + System.out.println("The title is: " + newNovel.getTitle()); + } +} diff --git a/Java/Activities/Activity6.java b/Java/Activities/Activity6.java new file mode 100644 index 0000000000..baf5c8e781 --- /dev/null +++ b/Java/Activities/Activity6.java @@ -0,0 +1,66 @@ +package Activity; + +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 passengerName) { + if(passengers.size() <= maxPassengers) { + this.passengers.add(passengerName); + } else { + System.out.println("Plane is full"); + } + } + + 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 { + + Plane plane = new Plane(10); + + plane.onboard("John"); + plane.onboard("Steve"); + plane.onboard("Anna"); + + System.out.println("Plane took off at: " + plane.takeOff()); + + System.out.println("People on the plane: " + plane.getPassengers()); + + Thread.sleep(5000); + + plane.land(); + + System.out.println("Plane landed at: " + plane.getLastTimeLanded()); + System.out.println("People on the plane after landing: " + plane.getPassengers()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity7.java b/Java/Activities/Activity7.java new file mode 100644 index 0000000000..0248380b6d --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,64 @@ +package Activity; + +interface BicycleParts { + public int tyres = 2; + public int maxSpeed = 25; +} + +interface BicycleOperations { + public void applyBrake(int decrement); + public void speedUp(int increment); +} + +class Bicycle implements BicycleParts, BicycleOperations { + + public int gears; + public int currentSpeed; + + public Bicycle(int gears, int currentSpeed) { + this.gears = gears; + this.currentSpeed = currentSpeed; + } + + 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); + } + + public String bicycleDesc() { + return("No of gears are "+ gears + "\nSpeed of bicycle is " + maxSpeed); + } +} + +class MountainBike extends Bicycle { + + public int seatHeight; + + public MountainBike(int gears, int currentSpeed, int startHeight) { + + super(gears, currentSpeed); + seatHeight = startHeight; + } + + public void setHeight(int newValue) { + seatHeight = newValue; + } + + public String bicycleDesc() { + return (super.bicycleDesc()+ "\nSeat height is " + seatHeight); + } +} + +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); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity8.java b/Java/Activities/Activity8.java new file mode 100644 index 0000000000..377e6fdbe6 --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,35 @@ +package Activity; + +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[] a){ + try { + + Activity8.exceptionTest("Will print to console"); + + Activity8.exceptionTest(null); + Activity8.exceptionTest("Won't execute"); + } catch(CustomException mae) { + System.out.println("Inside catch block: " + mae.getMessage()); + } + } + + static void exceptionTest(String str) throws CustomException { + if(str == null) { + throw new CustomException("String value is null"); + } else { + System.out.println(str); + } + } +} \ No newline at end of file diff --git a/Java/Activities/Activity9.java b/Java/Activities/Activity9.java new file mode 100644 index 0000000000..b7a7693bee --- /dev/null +++ b/Java/Activities/Activity9.java @@ -0,0 +1,29 @@ +package Activity; + +import java.util.ArrayList; + +public class Activity9 { + public static void main(String[] args) { + + ArrayList myList = new ArrayList(); + + myList.add("Apple"); + myList.add("Mango"); + myList.add("Orange"); + 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..5e4d664860 --- /dev/null +++ b/Java/Activities/Car.java @@ -0,0 +1,26 @@ +package Activity; + +public class Car { + //public class car { + int make; + String color; + String transmission; + int tyres = 4; + int doors = 4 ; + public void displayCharacterstics() { + // TODO Auto-generated method stub + System.out.println("Color of the Car: " + this.color); + System.out.println("Make of the Car: " + this.make); + System.out.println("Transmission of the Car: " + this.transmission); + System.out.println("Number of doors on the car: " + this.doors); + System.out.println("Number of tyres on the car: " + this.tyres); + } + public void accelerate() { + // TODO Auto-generated method stub + System.out.println("Car is moving forward."); + } + public void brake() { + // TODO Auto-generated method stub + System.out.println("Car has stopped."); + } + } \ No newline at end of file diff --git a/Java/Activities/Newfile.txt b/Java/Activities/Newfile.txt new file mode 100644 index 0000000000..70c379b63f --- /dev/null +++ b/Java/Activities/Newfile.txt @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/Python/Activities/Activity1.py b/Python/Activities/Activity1.py new file mode 100644 index 0000000000..280dcd5cfd --- /dev/null +++ b/Python/Activities/Activity1.py @@ -0,0 +1,5 @@ +name = input( "Enter your name: " ) +age = int( input( "Enter your age: " ) ) +year = ( 2025 - age ) + 100 + +print( "{} will turn 100 in the years {}.".format(name, year) ) diff --git a/Python/Activities/Activity10.py b/Python/Activities/Activity10.py new file mode 100644 index 0000000000..a1d96f842d --- /dev/null +++ b/Python/Activities/Activity10.py @@ -0,0 +1,8 @@ + +num_tuple = (10, 20, 33, 46, 55) +print("Given list is ", num_tuple) + +print("Elements that are divisible by 5:") +for num in num_tuple: + if (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..7764350ecd --- /dev/null +++ b/Python/Activities/Activity11.py @@ -0,0 +1,13 @@ +fruit_shop = { + "apple": 10, + "banana": 15, + "orange": 8, + "peaches": 15 +} + +key_to_check = input("What are you looking for? ").lower() + +if(key_to_check in fruit_shop): + print("Yes, this is available") +else: + print("No, this is not available") \ No newline at end of file diff --git a/Python/Activities/Activity12.py b/Python/Activities/Activity12.py new file mode 100644 index 0000000000..e803fa74c6 --- /dev/null +++ b/Python/Activities/Activity12.py @@ -0,0 +1,8 @@ + +def calculateSum(num): + if num: + return num + calculateSum(num-1) + else: + return 0 +res = calculateSum(10) +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..eecffa419f --- /dev/null +++ b/Python/Activities/Activity13.py @@ -0,0 +1,9 @@ + +def calculate_sum(numbers): + sum = 0 + for number in numbers: + sum += number + return sum +numList = [10, 40, 60, 90] +result = calculate_sum(numList) +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..0c824d80dc --- /dev/null +++ b/Python/Activities/Activity14.py @@ -0,0 +1,14 @@ +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..248db5aa0d --- /dev/null +++ b/Python/Activities/Activity15.py @@ -0,0 +1,4 @@ +try: + print(x) +except NameError: + print("x hasn't been defined yet.") diff --git a/Python/Activities/Activity16.py b/Python/Activities/Activity16.py new file mode 100644 index 0000000000..a4b0f60fa9 --- /dev/null +++ b/Python/Activities/Activity16.py @@ -0,0 +1,22 @@ +class Car: + 'This class represents a car' + + 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") + +car1.accelerate() +car1.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..71cd636576 --- /dev/null +++ b/Python/Activities/Activity17_18.py @@ -0,0 +1,34 @@ +# 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) + +# Print the DataFrame +print(dataframe) + +dataframe.to_csv("sample.csv", index=False) + +# Read the CSV file and store it into a DataFrame +dataframe = pandas.read_csv("sample.csv") + +# Print the values in the Usernames column only +print("Usernames:") +print(dataframe["Usernames"]) + +# Print the username and password of the second row +print("Username: ", dataframe["Usernames"][1], " | ", "Password: ", dataframe["Passwords"][1]) + +#Sort the Usernames column in ascending order +print("Data sorted in ascending Usernames:") +print(dataframe.sort_values('Usernames')) + +#Sort the Passwords column in descending order +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..294da27938 --- /dev/null +++ b/Python/Activities/Activity19_20.py @@ -0,0 +1,34 @@ +# 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) + +# Write the dataframe to a Excel file +writer = ExcelWriter('sample.xlsx') +dataframe.to_excel(writer, 'Sheet1', index = False) + +# Commit data to the Excel file +writer.close() + +# Read data from Excel sheet +dataframe = pandas.read_excel('sample.xlsx') + +# Print the number of rows and columns +print("Number of rows:", dataframe.shape[0]) +print("Number of columns:", dataframe.shape[1]) + +# Print the data in the emails column only +print(dataframe['Email']) + +# Sort the data based on FirstName in ascending order and print the 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..81d1737255 --- /dev/null +++ b/Python/Activities/Activity2.py @@ -0,0 +1,6 @@ +num = int(input("Enter a number: ")) +mod = num % 2 +if mod > 0: + print("You picked an odd number.") +else: + print("You picked an even number.") \ No newline at end of file diff --git a/Python/Activities/Activity3_4.py b/Python/Activities/Activity3_4.py new file mode 100644 index 0000000000..1c1b8fcda1 --- /dev/null +++ b/Python/Activities/Activity3_4.py @@ -0,0 +1,42 @@ +# Get the users names +user1 = input("What is Player 1's name? ") +user2 = input("What is Player 2's name? ") + +# Get the users choices +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.") + + # 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"): + raise SystemExit + # If they say anything else, exit with an error message. + else: + print("You entered an invalid option. Exiting now.") + raise SystemExit \ No newline at end of file diff --git a/Python/Activities/Activity5.py b/Python/Activities/Activity5.py new file mode 100644 index 0000000000..5d32db4f36 --- /dev/null +++ b/Python/Activities/Activity5.py @@ -0,0 +1,3 @@ +number = int(input("Input a number: ")) +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..b08461fbdb --- /dev/null +++ b/Python/Activities/Activity6.py @@ -0,0 +1,2 @@ +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..4c404db27d --- /dev/null +++ b/Python/Activities/Activity7.py @@ -0,0 +1,7 @@ +num = list(input("Enter a list of numbers: ").split(", ")) +sum = 0 + +for num in num: + sum += int(num) + +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..bbd7d3eafe --- /dev/null +++ b/Python/Activities/Activity8.py @@ -0,0 +1,10 @@ +numList = [10, 20, 30, 40, 10] +print("Given list is ", numList) + +firstElement = numList[0] +lastElement = numList[-1] + +if (firstElement == lastElement): + print(True) +else: + print(False) \ No newline at end of file diff --git a/Python/Activities/Activity9.py b/Python/Activities/Activity9.py new file mode 100644 index 0000000000..c6e7a33545 --- /dev/null +++ b/Python/Activities/Activity9.py @@ -0,0 +1,16 @@ +listOne = [10, 20, 23, 11, 17] +listTwo = [13, 43, 24, 36, 12] +print("First List ", listOne) +print("Second List ", listTwo) +thirdList = [] + +for num in listOne: + if (num % 2 != 0): + thirdList.append(num) + +for num in listTwo: + if (num % 2 == 0): + thirdList.append(num) + +print("result List is:") +print(thirdList) \ 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..f85cd38340 --- /dev/null +++ b/Python/Activities/activity21_22_test.py @@ -0,0 +1,33 @@ +import pytest + +# Additon test +@pytest.mark.activity +def test_addition(): + num1 = 10 + num2 = 15 + sum = num1 + num2 + assert sum == 25 + +# Subtraction test +@pytest.mark.activity +def test_subtraction(): + num1 = 50 + num2 = 35 + diff = num1 - num2 + assert diff == 15 + +# Multiplication test +@pytest.mark.activity +def test_multiplication(): + num1 = 5 + num2 = 20 + prod = num1 * num2 + assert prod == 100 + +# Division test +@pytest.mark.activity +def test_division(): + num1 = 100 + num2 = 5 + quot = num1 / num2 + 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..27c1536e84 --- /dev/null +++ b/Python/Activities/activity23_test.py @@ -0,0 +1,15 @@ +import pytest + + +# Write test method +def test_sum(num_list): + + # Initialize sum + sum = 0 + + # Add number in the list + for n in num_list: + sum += n + + # Assertion + 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..75a9bc29dd --- /dev/null +++ b/Python/Activities/activity24_test.py @@ -0,0 +1,17 @@ +import pytest + +@pytest.mark.activity +@pytest.mark.parametrize("earned, spent, expected", [ (30, 10, 20), (20, 2, 18), ]) +def test_transactions(wallet_amount, earned, spent, expected): + + print("wallet amount:", wallet_amount) + # Add money to your wallet + wallet_amount += earned + print("wallet amount, after earning:", wallet_amount) + + # Subtract amount from wallet + wallet_amount -= spent + print("wallet amount, after spending:", wallet_amount) + + # Assertion + assert wallet_amount == expected \ No newline at end of file diff --git a/Python/Activities/pandasexample.py b/Python/Activities/pandasexample.py new file mode 100644 index 0000000000..0fa40c9f3a --- /dev/null +++ b/Python/Activities/pandasexample.py @@ -0,0 +1,15 @@ +# import pandas +import pandas + +# Structure our data as a dictionary +data = { + "Vehicle Type": ["Car", "Car", "Bike"], + "Manufacturer": ["Maruti", "Toyota", "Royal Enfield"], + "Model": ["Swift", "Corolla", "Thunderbird"] +} + +# Create a new DataFrame using the data +dataframe = pandas.DataFrame(data) + +# Write the data to a csv file +dataframe.to_csv("vehicles.csv") \ No newline at end of file diff --git a/SQL/Activities/FST_sql(1-5).sql b/SQL/Activities/FST_sql(1-5).sql new file mode 100644 index 0000000000..29d5082d27 --- /dev/null +++ b/SQL/Activities/FST_sql(1-5).sql @@ -0,0 +1,39 @@ +-- Activity 1 +DROP TABLE salesman; +CREATE TABLE salesman(salesman_id int, salesman_name varchar(32), salesman_city varchar(32), commission int); +DESCRIBE salesman; + +-- Activity 2 + +INSERT ALL +INTO salesman VALUES(5001,'James Hoog', 'New York',15) + INTO salesman VALUES(5001,'Hoog', 'New York',15) + INTO salesman VALUES(5002,'Nail Knite','Paris',13) + INTO salesman VALUES(5005,'Pit Alex','London',12) + INTO salesman VALUES(5005,'Alex','London',10) + INTO salesman VALUES(5006,'McLyon','Paris',14) + INTO salesman VALUES(5007,'Paul Adam', 'Rome',16) + SELECT 1 FROM DUAL; +SELECT * FROM salesman; + +-- Activity 3 +-- Show data from the salesman_id and city columns +SELECT salesman_id, salesman_city FROM salesman; +-- Show data of salesman from Paris +SELECT * FROM salesman WHERE salesman_city='Paris'; +-- Show salesman_id and commission of Paul Adam +SELECT salesman_id, commission FROM salesman WHERE salesman_name='Paul Adam'; + + -- Activity 4 + -- Add the grade column +ALTER TABLE salesman ADD grade int; +-- Update the values in the grade column +UPDATE salesman SET grade=88; +-- Display data +SELECT * FROM salesman; + +-- Actiity 5 +UPDATE salesman SET grade=200 WHERE salesman_city ='Rome'; +UPDATE salesman SET grade=300 WHERE salesman_city ='New York'; +UPDATE salesman SET salesman_name='James Hoog' WHERE salesman_name ='Alex'; +SELECT * FROM salesman; diff --git a/SQL/Activities/FST_sql(6-8).sql b/SQL/Activities/FST_sql(6-8).sql new file mode 100644 index 0000000000..83d95d298b --- /dev/null +++ b/SQL/Activities/FST_sql(6-8).sql @@ -0,0 +1,37 @@ +-- Actiity 6 + +-- Get all salesman ids without any repeated values +select distinct salesman_id from orders; +-- Display the order number ordered by date in ascending order +select order_no, order_date from orders order by order_date; +-- Display the order number ordered by purchase amount in descending order +select order_no, purchase_amount from orders order by purchase_amount DESC; +-- Display the full data of orders that have purchase amount less than 500. +select * from orders where purchase_amount < 500; +-- Display the full data of orders that have purchase amount between 1000 and 2000. +select * from orders where purchase_amount between 1000 and 2000; + + +-- Actiity 7 + +-- Write an SQL statement to find the total purchase amount of all orders. +select SUM(purchase_amount) AS "Total sum" from orders; +-- Write an SQL statement to find the average purchase amount of all orders. +select AVG(purchase_amount) AS "Average" from orders; +-- Write an SQL statement to get the maximum purchase amount of all the orders. +select MAX(purchase_amount) AS "Maximum" from orders; +-- Write an SQL statement to get the minimum purchase amount of all the orders. +select MIN(purchase_amount) AS "Minumum" from orders; +-- Write an SQL statement to find the number of salesmen listed in the table. +select COUNT(distinct salesman_id) AS "Total count" from orders; + +-- Actiity 8 + +-- Write an SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount. +SELECT customer_id, MAX(purchase_amount) AS "Max Amount" FROM orders GROUP BY customer_id; +-- Write an SQL statement to find the highest purchase amount on '2012-08-17' for each salesman with their ID. +SELECT salesman_id, order_date, MAX(purchase_amount) AS "Max Amount" FROM orders +WHERE order_date=To_DATE('2012/08/17', 'YYYY/MM/DD') GROUP BY salesman_id, order_date; +-- Write an SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have a higher purchase amount within the list 2030, 3450, 5760, and 6000. +SELECT customer_id, order_date, MAX(purchase_amount) AS "Max Amount" FROM orders +GROUP BY customer_id, order_date HAVING MAX(purchase_amount) IN(2030, 3450, 5760, 6000); diff --git a/SQL/Activities/FST_sql(9-11).sql b/SQL/Activities/FST_sql(9-11).sql new file mode 100644 index 0000000000..c2a74d0d87 --- /dev/null +++ b/SQL/Activities/FST_sql(9-11).sql @@ -0,0 +1,72 @@ +-- Actiity 9 + +-- Create the customers table +create table customers ( + customer_id int primary key, customer_name varchar(32), + city varchar(20), grade int, salesman_id int); + +-- Insert values into it +INSERT ALL + INTO customers VALUES (3002, 'Nick Rimando', 'New York', 100, 5001) + INTO customers VALUES (3007, 'Brad Davis', 'New York', 200, 5001) + INTO customers VALUES (3005, 'Graham Zusi', 'California', 200, 5002) + INTO customers VALUES (3008, 'Julian Green', 'London', 300, 5002) + INTO customers VALUES (3004, 'Fabian Johnson', 'Paris', 300, 5006) + INTO customers VALUES (3009, 'Geoff Cameron', 'Berlin', 100, 5003) + INTO customers VALUES (3003, 'Jozy Altidor', 'Moscow', 200, 5007) + INTO customers VALUES (3001, 'Brad Guzan', 'London', 300, 5005) +SELECT 1 FROM DUAL; + +-- Write an SQL statement to know which salesman are working for which customer. +SELECT a.customer_name AS "Customer Name", a.city, b.salesman_name AS "Salesman", b.commission FROM customers a +INNER JOIN salesman b ON a.salesman_id=b.salesman_id; + +-- Write an SQL statement to make a list of customers in ascending order with a salesman that have a grade less than 300 +SELECT a.customer_name, a.city, a.grade, b.salesman_name AS "Salesman", b.salesman_city FROM customers a +LEFT OUTER JOIN salesman b ON a.salesman_id=b.salesman_id WHERE a.grade<300 +ORDER BY a.customer_id; + +-- Write an SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission of more than 12% +SELECT a.customer_name AS "Customer Name", a.city, b.salesman_name AS "Salesman", b.commission FROM customers a +INNER JOIN salesman b ON a.salesman_id=b.salesman_id +WHERE b.commission>12; + +-- Write an SQL statement to find the following details of an order - order number, order date, purchase amount of order, which customer gives the order and which salesman works for that customer and commission rate they get for the order. +SELECT a.order_no, a.order_date, a.purchase_amount, b.customer_name AS "Customer Name", b.grade, c.salesman_name AS "Salesman", c.commission FROM orders a +INNER JOIN customers b ON a.customer_id=b.customer_id +INNER JOIN salesman c ON a.salesman_id=c.salesman_id; + +-- Actiity 10 + +-- Write a query to find all the orders issued against the salesman who may works for customer whose id is 3007. +SELECT * FROM orders +WHERE salesman_id=(SELECT DISTINCT salesman_id FROM orders WHERE customer_id=3007); +-- Write a query to find all orders attributed to a salesman in New York. +SELECT * FROM orders +WHERE salesman_id IN (SELECT salesman_id FROM salesman WHERE salesman_city='New York'); +-- Write a query to count the customers with grades above New York's average. +SELECT grade, COUNT(*) FROM customers +GROUP BY grade HAVING grade>(SELECT AVG(grade) FROM customers WHERE city='New York'); +-- Write a query to extract the data from the orders table for those salesman who earned the maximum commission +SELECT order_no, purchase_amount, order_date, salesman_id FROM orders +WHERE salesman_id IN( SELECT salesman_id FROM salesman +WHERE commission=( SELECT MAX(commission) FROM salesman)); + +-- Actiity 11 + +-- Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order +SELECT customer_id, customer_name FROM customers a +WHERE 1<(SELECT COUNT(*) FROM orders b WHERE a.customer_id = b.customer_id) +UNION +SELECT salesman_id, salesman_name FROM salesman a +WHERE 1<(SELECT COUNT(*) FROM orders b WHERE a.salesman_id = b.salesman_id) +ORDER BY customer_name; +-- Write a query to make a report of which salesman produce the largest and smallest orders on each date. +SELECT a.salesman_id, a.salesman_name, o.order_no, 'highest on', o.order_date, o.purchase_amount FROM salesman a, orders o +WHERE a.salesman_id=o.salesman_id +AND o.purchase_amount=(SELECT MAX(purchase_amount) FROM orders c WHERE c.order_date = o.order_date) +UNION +SELECT a.salesman_id, a.salesman_name, o.order_no, 'lowest on', o.order_date, o.purchase_amount FROM salesman a, orders o +WHERE a.salesman_id=o.salesman_id +AND o.purchase_amount=(SELECT MIN(purchase_amount) FROM orders c WHERE c.order_date = o.order_date) +ORDER BY order_date; diff --git a/Selenium/Activity1.java b/Selenium/Activity1.java new file mode 100644 index 0000000000..37da2306bc --- /dev/null +++ b/Selenium/Activity1.java @@ -0,0 +1,23 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity1 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net"); + + System.out.println("Page title is: " + driver.getTitle()); + driver.findElement(By.linkText("About Us")).click(); + System.out.println("New page title is: " + driver.getTitle()); + + + driver.quit(); + + } + +} diff --git a/Selenium/Activity10.java b/Selenium/Activity10.java new file mode 100644 index 0000000000..1f26bad708 --- /dev/null +++ b/Selenium/Activity10.java @@ -0,0 +1,30 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity10 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + Actions builder = new Actions(driver); + driver.get("https://training-support.net/webelements/drag-drop"); + System.out.println("Page title: " + driver.getTitle()); + WebElement football = driver.findElement(By.id("ball")); + WebElement dropzone1 = driver.findElement(By.id("dropzone1")); + WebElement dropzone2 = driver.findElement(By.id("dropzone2")); + 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"); + } + 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"); + } + driver.quit(); + } + +} diff --git a/Selenium/Activity12.java b/Selenium/Activity12.java new file mode 100644 index 0000000000..eb4dbc0d31 --- /dev/null +++ b/Selenium/Activity12.java @@ -0,0 +1,24 @@ +package Activity; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity12 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + driver.get("https://www.training-support.net/webelements/dynamic-content"); + System.out.println("Page title: " + driver.getTitle()); + driver.findElement(By.id("genButton")).click(); + if (wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("word"), "release"))) { + System.out.println("Word found: " + driver.findElement(By.id("word")).getText()); + } + driver.quit(); + } + +} diff --git a/Selenium/Activity13.java b/Selenium/Activity13.java new file mode 100644 index 0000000000..cb456aa0bb --- /dev/null +++ b/Selenium/Activity13.java @@ -0,0 +1,31 @@ +package Activity; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + + +public class Activity13 { + + public static void main(String[] args) { + + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/tables"); + System.out.println("Page title: " + driver.getTitle()); + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of rows: " + rows.size()); + 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()); + } + 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()); + driver.quit(); + } + +} diff --git a/Selenium/Activity14.java b/Selenium/Activity14.java new file mode 100644 index 0000000000..a667b429d9 --- /dev/null +++ b/Selenium/Activity14.java @@ -0,0 +1,28 @@ +package Activity; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + + +public class Activity14 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/tables"); + System.out.println("Page title: " + driver.getTitle()); + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of rows: " + rows.size()); + 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()); + driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th[5]")).click(); + cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book Name after sorting: " + cellValue.getText()); + driver.quit(); + } + +} diff --git a/Selenium/Activity15.java b/Selenium/Activity15.java new file mode 100644 index 0000000000..de1e41fd6b --- /dev/null +++ b/Selenium/Activity15.java @@ -0,0 +1,33 @@ +package Activity; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity15 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + driver.get("https://training-support.net/webelements/dynamic-attributes"); + System.out.println("Page title is: " + driver.getTitle()); + 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-')]")); + fullName.sendKeys("vinod"); + email.sendKeys("vinod@example.com"); + eventDate.sendKeys("2025-03-15"); + details.sendKeys("End of course party"); + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + String message = driver.findElement(By.id("action-confirmation")).getText(); + //wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("action-confirmation"))) .getText(); + System.out.println("Success message: " + message); + driver.quit(); + } + +} diff --git a/Selenium/Activity16.java b/Selenium/Activity16.java new file mode 100644 index 0000000000..fdc1a14b1b --- /dev/null +++ b/Selenium/Activity16.java @@ -0,0 +1,34 @@ +package Activity; + +import java.util.List; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.Select; + + +public class Activity16 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/selects"); + System.out.println("Page title is: " + driver.getTitle()); + WebElement dropdown = driver.findElement(By.cssSelector("select.h-10")); + Select singleSelect = new Select(dropdown); + singleSelect.selectByVisibleText("Two"); + System.out.println("Second option: " + singleSelect.getFirstSelectedOption().getText()); + singleSelect.selectByIndex(3); + System.out.println("Third option: " + singleSelect.getFirstSelectedOption().getText()); + singleSelect.selectByValue("four"); + System.out.println("Fourth option: " + singleSelect.getFirstSelectedOption().getText()); + List allOptions = singleSelect.getOptions(); + System.out.println("Options in the dropdown: "); + for(WebElement option : allOptions) { + System.out.println(option.getText()); + } + driver.quit(); + } + + +} diff --git a/Selenium/Activity18.java b/Selenium/Activity18.java new file mode 100644 index 0000000000..d828a7d801 --- /dev/null +++ b/Selenium/Activity18.java @@ -0,0 +1,24 @@ +package Activity; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + + +public class Activity18 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/alerts"); + System.out.println("Page title: " + driver.getTitle()); + driver.findElement(By.id("simple")).click(); + Alert simpleAlert = driver.switchTo().alert(); + String alertText = simpleAlert.getText(); + System.out.println("Text in alert: " + alertText); + simpleAlert.accept(); + System.out.println(driver.findElement(By.id("result")).getText()); + driver.quit(); + } + +} diff --git a/Selenium/Activity19.java b/Selenium/Activity19.java new file mode 100644 index 0000000000..5ae82131a4 --- /dev/null +++ b/Selenium/Activity19.java @@ -0,0 +1,24 @@ +package Activity; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity19 { + + public static void main(String[] args) { + + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/alerts"); + System.out.println("Page title: " + driver.getTitle()); + driver.findElement(By.id("confirm")).click(); + Alert confirmAlert = driver.switchTo().alert(); + String alertText = confirmAlert.getText(); + System.out.println("Text in alert: " + alertText); + confirmAlert.accept(); + System.out.println(driver.findElement(By.id("result")).getText()); + driver.quit(); + } + +} diff --git a/Selenium/Activity2.java b/Selenium/Activity2.java new file mode 100644 index 0000000000..077fe972e8 --- /dev/null +++ b/Selenium/Activity2.java @@ -0,0 +1,27 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + + +public class Activity2 { + + public static void main(String[] args) throws InterruptedException { + // TODO Auto-generated method stub + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/login-form"); + + System.out.println("Page title: " + driver.getTitle()); + driver.findElement(By.id("username")).sendKeys("admin"); + driver.findElement(By.id("password")).sendKeys("password"); + driver.findElement(By.cssSelector("button.svelte-1pdjkmx")).click(); + //Thread.sleep(1000); + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println(message); + driver.quit(); + + } + +} diff --git a/Selenium/Activity21.java b/Selenium/Activity21.java new file mode 100644 index 0000000000..e1d01b8d22 --- /dev/null +++ b/Selenium/Activity21.java @@ -0,0 +1,36 @@ +package Activity; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity21 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + driver.get("https://training-support.net/webelements/tabs"); + System.out.println("Page title: " + driver.getTitle()); + System.out.println("Current tab: " + driver.getWindowHandle()); + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Open A New Tab']"))).click(); + wait.until(ExpectedConditions.numberOfWindowsToBe(2)); + System.out.println("Currently open windows: " + driver.getWindowHandles()); + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(), 'Another One')]"))); + System.out.println("Current tab: " + driver.getWindowHandle()); + System.out.println("New Page title: " + driver.getTitle()); + System.out.println("New Page message: " + driver.findElement(By.cssSelector("h2.mt-5")).getText()); + driver.findElement(By.xpath("//button[contains(text(), 'Another One')]")).click(); + wait.until(ExpectedConditions.numberOfWindowsToBe(3)); + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + driver.quit(); + } + +} diff --git a/Selenium/Activity3.java b/Selenium/Activity3.java new file mode 100644 index 0000000000..806c3e48c4 --- /dev/null +++ b/Selenium/Activity3.java @@ -0,0 +1,28 @@ +package Activity; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity3 { + + public static void main(String[] args) { + // Initialize the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // 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(); + String message = driver.findElement(By.xpath("//h1[contains(text(), 'Success')]")).getText(); + System.out.println(message); + + driver.quit(); + } +} diff --git a/Selenium/Activity8.java b/Selenium/Activity8.java new file mode 100644 index 0000000000..562ffa6716 --- /dev/null +++ b/Selenium/Activity8.java @@ -0,0 +1,32 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + + +public class Activity8 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + Actions builder = new Actions(driver); + driver.get("https://training-support.net/webelements/mouse-events"); + System.out.println("Page title: " + driver.getTitle()); + 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']")); + builder.click(cargoLock).pause(1000).moveToElement(cargoToml).pause(5000).click(cargoToml).build().perform(); + String actionMessage = driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + builder.doubleClick(srcButton).pause(3000).pause(5000) + .contextClick(targetButton).pause(3000).build().perform(); + builder.click(driver.findElement(By.xpath("//div[@id='menu']/div/ul/li[1]"))).pause(5000).build().perform(); + actionMessage = driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + driver.quit(); + } + +} diff --git a/TestNG/Activities/Activity1.java b/TestNG/Activities/Activity1.java new file mode 100644 index 0000000000..0067bd887d --- /dev/null +++ b/TestNG/Activities/Activity1.java @@ -0,0 +1,43 @@ +package Activity; + +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.firefox.FirefoxDriver; +import org.testng.annotations.AfterClass; + +public class Activity1 { + + WebDriver driver; + + @BeforeClass + public void setUp() { + // WebDriverManager.firefox().setup(); + driver = new FirefoxDriver(); + + driver.get("https://training-support.net/"); + } + + @Test(priority = 1) + public void pageTitleTest() { + + assertEquals(driver.getTitle(), "About Training Support"); + } + + @Test(priority = 2) + public void aboutLinkTest() { + driver.findElement(By.linkText("About Us")).click(); + assertEquals(driver.getTitle(), "About Training Support"); + + } + + @AfterClass + public void afterMethod() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity10.java b/TestNG/Activities/Activity10.java new file mode 100644 index 0000000000..badffc534a --- /dev/null +++ b/TestNG/Activities/Activity10.java @@ -0,0 +1,93 @@ +package Activity; + +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.firefox.FirefoxDriver; +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 FirefoxDriver(); + 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/java/Activity/employees.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(1)); + // Enter the email + driver.findElement(By.id("email")).sendKeys(rows.get(2)); + // Enter the Date of the event + driver.findElement(By.name("event-date")).sendKeys(rows.get(3).replaceAll("\"", "")); + // Enter additional details + driver.findElement(By.id("additional-details")).sendKeys(rows.get(4)); + // 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!"); + // Refresh the page + driver.navigate().refresh(); + } + + @AfterClass + public void tearDown() { + // Close the browser + //driver.quit(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity2.java b/TestNG/Activities/Activity2.java new file mode 100644 index 0000000000..9367a2510d --- /dev/null +++ b/TestNG/Activities/Activity2.java @@ -0,0 +1,51 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +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 FirefoxDriver(); + // 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"), "Subheading does not contain '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..837b864f89 --- /dev/null +++ b/TestNG/Activities/Activity3.java @@ -0,0 +1,38 @@ +package Activity; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +public class Activity3 { + WebDriver driver; + @BeforeClass + public void beforeClass() { + driver = new FirefoxDriver(); + // Open browser + driver.get("https://training-support.net/webelements/login-form"); + } + @Test + public void loginTest() { + // Find the username and password fields + WebElement username = driver.findElement(By.id("username")); + WebElement password = driver.findElement(By.id("password")); + // Enter credentials + username.sendKeys("admin"); + password.sendKeys("password"); + // Click login + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + // Read 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/Activity4_DemoOne.java b/TestNG/Activities/Activity4_DemoOne.java new file mode 100644 index 0000000000..4650f25d03 --- /dev/null +++ b/TestNG/Activities/Activity4_DemoOne.java @@ -0,0 +1,15 @@ +package Activity; + +import org.testng.annotations.Test; + +public class Activity4_DemoOne { + @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"); + } +} diff --git a/TestNG/Activities/Activity4_DemoTwo.java b/TestNG/Activities/Activity4_DemoTwo.java new file mode 100644 index 0000000000..17f406b9cc --- /dev/null +++ b/TestNG/Activities/Activity4_DemoTwo.java @@ -0,0 +1,10 @@ +package Activity; + +import org.testng.annotations.Test; + +public class Activity4_DemoTwo { + @Test + public void TestCase() { + System.out.println("I'm in the test case from DemoTwo Class"); + } +} diff --git a/TestNG/Activities/Activity5.java b/TestNG/Activities/Activity5.java new file mode 100644 index 0000000000..0cce8d43d1 --- /dev/null +++ b/TestNG/Activities/Activity5.java @@ -0,0 +1,55 @@ +package Activity; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +public class Activity5 { + WebDriver driver; + //Include alwaysRun property on the @BeforeTest + //to make sure the page opens + @BeforeTest(alwaysRun = true) + public void beforeMethod() { + // Set up the Firefox driver + //Create a new instance of the Firefox driver + driver = new FirefoxDriver(); + //Open the browser + driver.get("https://v1.training-support.net/selenium/target-practice"); + } + @Test (groups = {"HeaderTests", "ButtonTests"}) + public void pageTitleTest() { + String title = driver.getTitle(); + System.out.println("Title is: " + title); + Assert.assertEquals(title, "Target Practice"); + } + @Test (dependsOnMethods = {"pageTitleTest"}, groups = {"HeaderTests"}) + public void HeaderTest1() { + WebElement header3 = driver.findElement(By.cssSelector("h3#third-header")); + Assert.assertEquals(header3.getText(), "Third header"); + } + @Test (dependsOnMethods = {"pageTitleTest"}, groups = {"HeaderTests"}) + public void HeaderTest2() { + WebElement header5 = driver.findElement(By.cssSelector("h3#third-header")); + Assert.assertEquals(header5.getCssValue("color"), "rgb(251, 189, 8)"); + } + @Test (dependsOnMethods = {"pageTitleTest"}, groups = {"ButtonTests"}) + public void ButtonTest1() { + WebElement button1 = driver.findElement(By.cssSelector("button.olive")); + Assert.assertEquals(button1.getText(), "Olive"); + } + @Test(dependsOnMethods = {"pageTitleTest"}, groups = {"ButtonTests"}) + public void ButtonTest2() { + WebElement button2 = driver.findElement(By.cssSelector("button.brown")); + Assert.assertEquals(button2.getCssValue("color"), "rgb(255, 255, 255)"); + } + //Include alwaysRun property on the @AfterTest + //to make sure the page closes + @AfterTest(alwaysRun = true) + public void afterMethod() { + //Close the browser + 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..3af61631ca --- /dev/null +++ b/TestNG/Activities/Activity6.java @@ -0,0 +1,50 @@ +package Activity; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +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 Firefox driver + driver = new FirefoxDriver(); + // 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..1bd6fd1715 --- /dev/null +++ b/TestNG/Activities/Activity7.java @@ -0,0 +1,84 @@ +package Activity; +import static org.testng.Assert.assertEquals; +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +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.DataProvider; +import org.testng.annotations.Test; +public class Activity7 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + //driver initilization + driver = new FirefoxDriver(); + // Initialize wait object + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + //open the browser + driver.get("https://training-support.net/webelements/login-form"); + } + @Test(priority=1) + public void pageTitleTest() { + //verifying page title + assertEquals(driver.getTitle(), "Selenium: Login Form"); + } + @DataProvider(name="BadCredentials") + public Object[][] creds(){ + Object[][] credentials = { + {"admin", "wrongPassword", "Invalid credential"}, + {"wrongUser", "password","Invalid credential"}, + {"wrongUser", "WrongPassword","Invalid credential"}, + {" ", " ","Invalid credential"}, + }; + + return credentials; + } + + @Test(dataProvider ="BadCredentials", priority=2) + public void failLoginTest(String username, String password, String expectedMessage) { + //find the form elements + driver.navigate().refresh(); + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + WebElement submitButton = driver.findElement(By.xpath("//button[text()='Submit']")); + + //clear the input field + //wait.until(ExpectedConditions.elementToBeClickable(submitButton)); + usernameField.clear(); + passwordField.clear(); + + //enter the value and click submit + usernameField.sendKeys(username); + passwordField.sendKeys(password); + submitButton.click(); + + try { + Thread.sleep(5000); + + }catch(InterruptedException e) { + e.printStackTrace(); + + + //verifying the message + String loginMessage = driver.findElement(By.id("subheading")).getText(); + Assert.assertEquals(loginMessage,expectedMessage); + } + } + @AfterClass + public void tearDown() { + //closer 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..e97f9ece70 --- /dev/null +++ b/TestNG/Activities/Activity9.java @@ -0,0 +1,95 @@ +package Activity; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +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() { + // Create a new instance of the Firefox driver + driver = new FirefoxDriver(); + 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(); + } +} diff --git a/TestNG/Activities/testng.xml b/TestNG/Activities/testng.xml new file mode 100644 index 0000000000..9f2d00850e --- /dev/null +++ b/TestNG/Activities/testng.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + +