Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cucumber/Activities/Activity2.feature
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions Cucumber/Activities/Activity3.feature
Original file line number Diff line number Diff line change
@@ -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 <Type> 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 |
8 changes: 8 additions & 0 deletions Cucumber/Activities/Activity4.feature
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions Cucumber/Activities/Activity5.feature
Original file line number Diff line number Diff line change
@@ -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 "<Usernames>" and "<Passwords>"
And clicks the submit button
Then get the confirmation text and verify message as "<Message>"
Examples:
| Usernames | Passwords | Message |
| admin | password | Welcome Back, Admin! |
| admin | WrongPassword | Invalid credentials |
9 changes: 9 additions & 0 deletions Cucumber/Activities/Activity6.feature
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions Cucumber/Activities/AlertTestSteps.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions Cucumber/Activities/BaseClass.java
Original file line number Diff line number Diff line change
@@ -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;

}
30 changes: 30 additions & 0 deletions Cucumber/Activities/DataTableExampleSteps.java
Original file line number Diff line number Diff line change
@@ -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<String> 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");
}
}
6 changes: 6 additions & 0 deletions Cucumber/Activities/FirstTest.feature
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions Cucumber/Activities/FirstTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
21 changes: 21 additions & 0 deletions Cucumber/Activities/Fixture.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
70 changes: 70 additions & 0 deletions Cucumber/Activities/LoginSteps.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
28 changes: 28 additions & 0 deletions Cucumber/Activities/TestRunner.java
Original file line number Diff line number Diff line change
@@ -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 {

}





15 changes: 15 additions & 0 deletions Java/Activities/Activity1.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
32 changes: 32 additions & 0 deletions Java/Activities/Activity10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Activity;

import java.util.HashSet;

public class Activity10 {
public static void main(String[] args) {
HashSet<String> hs = new HashSet<String>();

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);
}
}
Loading