Created
January 18, 2024 03:44
-
-
Save Sakib62/c7f95729e72f8d8611e116ca7ccc4cde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
public class Testing { | |
WebDriver webDriver; | |
public WebDriver getWebDriver() { | |
return webDriver; | |
} | |
public void loadWeb() throws InterruptedException { | |
webDriver = new ChromeDriver(); | |
webDriver.manage().window().maximize(); | |
webDriver.get("https://www.saucedemo.com/"); | |
Thread.sleep(2000); | |
} | |
public void login() throws InterruptedException { | |
webDriver.findElement(By.id("user-name")).sendKeys("performance_glitch_user"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("password")).sendKeys("secret_sauce"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("login-button")).click(); | |
Thread.sleep(2000); | |
} | |
public void backpack() throws InterruptedException { | |
webDriver.findElement(By.xpath("//*[@id=\"item_4_title_link\"]/div")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("back-to-products")).click(); | |
Thread.sleep(2000); | |
} | |
public void checkout() throws InterruptedException { | |
webDriver.findElement(By.className("shopping_cart_link")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.xpath("//*[@id=\"checkout\"]")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("first-name")).sendKeys("Sakibul"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("last-name")).sendKeys("Islam"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("postal-code")).sendKeys("7360"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("continue")).click(); | |
Thread.sleep(2000); | |
} | |
public void exit() { | |
webDriver.quit(); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
Testing test = new Testing(); | |
test.loadWeb(); | |
test.login(); | |
test.backpack(); | |
test.checkout(); | |
//test.exit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.example</groupId> | |
<artifactId>Mockito</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<properties> | |
<maven.compiler.source>17</maven.compiler.source> | |
<maven.compiler.target>17</maven.compiler.target> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.junit.jupiter</groupId> | |
<artifactId>junit-jupiter-engine</artifactId> | |
<version>5.9.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-core</artifactId> | |
<version>5.9.0</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-java</artifactId> | |
<version>4.16.1</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
public class Main { | |
WebDriver webDriver; | |
public void loadWeb() throws InterruptedException { | |
//System.setProperty("webdriver.gecko.driver", "C:\\Users\\User\\Downloads\\geckodriver-v0.34.0-win64\\geckodriver.exe"); | |
webDriver = new ChromeDriver(); | |
webDriver.get("https://book.spicejet.com/search.aspx"); | |
//webDriver.navigate().to("https://book.spicejet.com/search.aspx"); | |
Thread.sleep(2000); | |
} | |
public void selectDepartureCity() throws InterruptedException { | |
webDriver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1_CTXT")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.linkText("Chennai (MAA)")).click(); | |
Thread.sleep(2000); | |
} | |
public void selectArrivalCity() throws InterruptedException { | |
webDriver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchViewdestinationStation1_CTXT")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.linkText("Delhi (DEL)")).click(); | |
Thread.sleep(2000); | |
} | |
public void departureDate() throws InterruptedException { | |
webDriver.findElement(By.id("custom_date_picker_id_1")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.linkText("20")).click(); | |
Thread.sleep(2000); | |
} | |
public void currencySelect() throws InterruptedException { | |
webDriver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchView_DropDownListCurrency")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.cssSelector("option[value='BDT']")).click(); | |
Thread.sleep(2000); | |
} | |
public void searchFlight() throws InterruptedException { | |
webDriver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchView_ButtonSubmit")).click(); | |
Thread.sleep(2000); | |
} | |
public void exit() { | |
webDriver.quit(); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
Main bookingFlight = new Main(); | |
bookingFlight.loadWeb(); | |
bookingFlight.selectDepartureCity(); | |
bookingFlight.selectArrivalCity(); | |
bookingFlight.departureDate(); | |
bookingFlight.currencySelect(); | |
bookingFlight.searchFlight(); | |
//bookingFlight.exit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
public class SeleniumPractice { | |
WebDriver webDriver; | |
public void webSet() { | |
//System.setProperty("webdriver.gecko.driver", "C:\\Users\\User\\Downloads\\geckodriver-v0.34.0-win64\\geckodriver.exe"); | |
webDriver = new ChromeDriver(); | |
webDriver.get("https://www.saucedemo.com/"); | |
} | |
public void login() throws InterruptedException { | |
webDriver.findElement(By.id("user-name")).sendKeys("standard_user"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("password")).sendKeys("secret_sauce"); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("login-button")).click(); | |
Thread.sleep(2000); | |
} | |
public void sort() throws InterruptedException { | |
webDriver.findElement(By.className("product_sort_container")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.cssSelector("option[value='lohi']")).click(); | |
Thread.sleep(2000); | |
} | |
public void bikeAddToCart() throws InterruptedException { | |
webDriver.findElement(By.id("add-to-cart-sauce-labs-bike-light")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.className("shopping_cart_link")).click(); | |
Thread.sleep(2000); | |
webDriver.findElement(By.id("remove-sauce-labs-bike-light")).click(); | |
Thread.sleep(2000); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
SeleniumPractice seleniumPractice = new SeleniumPractice(); | |
seleniumPractice.webSet(); | |
seleniumPractice.login(); | |
seleniumPractice.sort(); | |
seleniumPractice.bikeAddToCart(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.Select; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import java.time.Duration; | |
import java.util.List; | |
public class BookScript { | |
WebDriver driver; | |
public void getDepurture(List<WebElement> countryElements, String depurtureCity) throws InterruptedException { | |
// Extract and print the text of each country | |
for (WebElement countryElement : countryElements) { | |
String countryText = countryElement.getText(); | |
System.out.println(countryText); | |
if(countryText.equals(depurtureCity)){ | |
countryElement.click(); | |
} | |
} | |
} | |
public void getArrival(List<WebElement> countryElements, String arrivalCity) throws InterruptedException { | |
for (WebElement countryElement : countryElements) { | |
String countryText = countryElement.getText(); | |
System.out.println(countryText); | |
if(countryText.equals(arrivalCity)){ | |
countryElement.click(); | |
} | |
} | |
} | |
public void selectDate(int day) throws InterruptedException { | |
WebElement dateElement = driver.findElement(By.xpath("//a[@data-date='" + day + "']")); | |
dateElement.click(); | |
} | |
public void selectCurrency(String currencyName) throws InterruptedException { | |
WebElement currency = driver.findElement(By.xpath("/html/body/div[19]/form/div[2]/div/div[2]/div[3]/div/div[4]/p/select")); | |
Select dropdownSelect = new Select(currency); | |
dropdownSelect.selectByVisibleText(currencyName); | |
} | |
public BookScript() throws InterruptedException { | |
driver = new ChromeDriver(); | |
driver.get("https://book.spicejet.com/search.aspx"); | |
// Locate the dropdown container element | |
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(5000)); | |
WebElement depurture = driver.findElement(By.name("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1_CTXT")); | |
depurture.click(); | |
WebElement dropdownContainer = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("dropdownGroup1"))); | |
java.util.List<WebElement> countryElements = dropdownContainer.findElements(By.cssSelector("ul li a")); | |
getDepurture(countryElements,"Chennai (MAA)"); | |
getArrival(countryElements, "Delhi (DEL)"); | |
selectDate(20); | |
selectCurrency("BDT"); | |
WebElement searchButton = driver.findElement(By.xpath("/html/body/div[19]/form/div[2]/div/div[2]/div[3]/div/div[11]/div/span/input")); | |
searchButton.click(); | |
// Close the browser | |
// driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment