0% found this document useful (0 votes)
45 views9 pages

Day 3 - Selenium Code For Usecases

Uploaded by

kalaimohan0405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views9 pages

Day 3 - Selenium Code For Usecases

Uploaded by

kalaimohan0405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Usecases

1. //AmazonLogin

package ApplicationTest;

import java.awt.RenderingHints.Key;
import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class AmazonLogin {

public static void main(String[] args) throws InterruptedException


{
System.getProperty("Webdriver.chromeDriver","\"D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe\"");

WebDriver driver2 = new ChromeDriver();

driver2.get("https://www.amazon.in");
driver2.manage().window().maximize();
driver2.findElement(By.id("nav-link-accountList")).click();

driver2.findElement(By.id("ap_email")).sendKeys("[email protected]"+Keys.ENTER);

driver2.findElement(By.id("ap_password")).sendKeys("Ingage@123"+Keys.ENTER);
driver2.findElement(By.id("twotabsearchtextbox")).sendKeys("musical
keyboard"+Keys.ENTER);

driver2.findElement(By.xpath("//*[@id=\"p_89/YAMAHA\"]/span/a/span")).click();

Thread.sleep(2000);

driver2.findElement(By.xpath("//*[@id=\"search\"]/div[1]/div[1]/div/
span[1]/div[1]/div[2]/div/div/span/div/div/div[1]/span/a/div/img")).click();

List<String> tabs= new ArrayList<String>(driver2.getWindowHandles());


Thread.sleep(2000);

driver2.switchTo().window(tabs.get(tabs.size()-2));

Thread.sleep(2000);

driver2.switchTo().window(tabs.get(tabs.size()-1));
driver2.findElement(By.name("field-keywords")).clear();
driver2.findElement(By.name("field-keywords")).sendKeys("acoustic
guitars"+Keys.ENTER);
driver2.findElement(By.xpath("//*[@id=\"search\"]/div[1]/div[1]/div/
span[1]/div[1]/div[4]/div/div/div/div/span/div/div/div[1]/span/a/div/
img")).click();
driver2.findElement(By.xpath("//*[@id=\"buy-now-button\"]")).click();

// TODO Auto-generated method stub

}
//

2.// TicketBooking

package ApplicationTest;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;

import org.openqa.selenium.chrome.ChromeDriver;

public class BookingTest {

public static void main(String[] args) throws InterruptedException


{
System.getProperty("webdriver.chrome.driver","D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();

opt.addArguments("--disable-popup-blocking");
opt.addArguments("--disable-notifications");

WebDriver booking = new ChromeDriver(opt);

booking.get("https://www.redbus.in/");
booking.manage().window().maximize();

Thread.sleep(2000);

// booking.findElement(By.id("src")).sendKeys("chennai"+Keys.ENTER);
// booking.findElement(By.id("dest")).sendKeys("karaikal"+Keys.ENTER);
// booking.findElement(By.id("onwardCal")).sendKeys("20012024");

booking.findElement(By.id("cab_rental_vertical")).click();

booking.findElement(By.xpath("//*[@id=\"reactContentMount\"]/div/div[1]/div/
div/div/div[1]/div[3]/a")).click();

Thread.sleep(2000);
booking.findElement(By.xpath("//*[@id=\"root\"]/section[1]/div/div[3]/
div[1]/div[3]")).click();

Thread.sleep(2000);

booking.findElement(By.name("pnrNo")).sendKeys("12606");

Thread.sleep(6000);

booking.findElement(By.xpath("//*[@id=\"root\"]/div/section/div[2]/
div[4]/div/div")).click();

Thread.sleep(2000);

booking.findElement(By.xpath("//*[@id=\"root\"]/div/section/div[2]/
div[4]/button")).click();

// TODO Auto-generated method stub

//

//3. Facebook Login

package ApplicationTest;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FacebookTest {

public static void main(String[] args)


{

System.getProperty("Webdriver.chromeDriver","D:\\Software testing\\chromedriver-
win64\\chromedriver-win64\\chromedriver.exe");

WebDriver driver1 = new ChromeDriver();

driver1.get("https://www.facebook.com/");
driver1.manage().window().maximize();
driver1.findElement(By.id("email")).sendKeys("7904585024"+Keys.ENTER);
driver1.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
driver1.findElement(By.name("pass")).sendKeys("Kaasvika@29"+Keys.ENTER);
// TODO Auto-generated method stub

//

// 4. Flipkart

package ApplicationTest;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Flipkart1Tesst {

public static void main(String[] args)


{
System.getProperty("webdriver.chrome.driver","D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe");
WebDriver driver1= new ChromeDriver();

driver1.get("https://www.flipkart.com/realme-11x-5g-midnight-black-128-
gb/p/itm07be1a2ff1a1b?
pid=MOBGS2WFP7X8263G&lid=LSTMOBGS2WFP7X8263G7TE3WT&marketplace=FLIPKART&store=tyy
%2F4io&srno=b_1_1&otracker=nmenu_sub_Electronics_0_Realme&fm=organic&iid=4c7cecd8-
1c86-43af-9b75-0922853d0243.MOBGS2WFP7X8263G.SEARCH&ppt=clp&ppn=mobile-phones-
store&ssid=ozx04az5kw0000001704366596883");
driver1.manage().window().maximize();
//driver1.findElement(By.className("_1KOMV2")).click();
driver1.findElement(By.className("_3iRXzi")).click();

//driver1.get("https://www.flipkart.com");
//driver1.findElement(By.xpath("//*[@id=\"container\"]/div/div[1]/div/
div/div/div/div[1]/div/div[1]/div/div[1]/div[1]/header/div[1]/div[2]/form/div/div/
input")).sendKeys("mobiles"+Keys.ENTER);
//driver1.findElement(By.xpath("//*[@id=\"container\"]/div/div[3]/
div[1]/div[2]/div[7]/div/div/div/a/div[1]/div[1]/div/div/img")).click();
//driver1.findElement(By.className("_396cs4")).click();

}
// TODO Auto-generated method st

//

// 5. Gmail Login
package ApplicationTest;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GmailTest {

public static void main(String[] args)


{

System.getProperty("Webdriver.chromeDriver","D:\\Software testing\\chromedriver-
win64\\chromedriver-win64\\chromedriver.exe");

WebDriver driver1 = new ChromeDriver();

driver1.get("https://www.gmail.com");
driver1.manage().window().maximize();

driver1.findElement(By.xpath("//*[@id=\"identifierId\"]"));

driver1.findElement(By.xpath("//*[@id=\"identifierId\"]")).sendKeys("jeyakumar@myin
gage.com"+Keys.ENTER);

//driver1.findElement(By.xpath("//*[@id=\"yDmH0d\"]/div[2]/c-wiz/div[1]/div/
div[1]/div[1]/div/div/a[1]")).click();

//driver1.findElement(By.xpath("//*[@id=\"rso\"]/div[1]/div/div/div[1]/div/
div/span/a/h3")).click();

//driver1.findElement(By.xpath("/html/body/header/div/div/div/a[2]")).click();

// TODO Auto-generated method stub

}
//

// 6. Google Keyword Search

package ApplicationTest;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleTest {

public static void main(String[] args)


{
System.getProperty("webdriver.chrome.driver","D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe");
WebDriver driver1= new ChromeDriver();
driver1.get("https://www.google.com/");
driver1.manage().window().maximize();
driver1.findElement(By.id("APjFqb")).sendKeys("Ingage
Technologies"+Keys.ENTER);
driver1.findElement(By.partialLinkText("myingage.com")).click();
// TODO Auto-generated method stub

}
//

// 7. online LearningPF

package ApplicationTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LearningPF {

public static void main(String[] args) throws InterruptedException


{
System.getProperty("webdriver.chrome.driver","D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe");

WebDriver byjus = new ChromeDriver();

byjus.get("https://byjus.com/");
byjus.manage().window().maximize();

Thread.sleep(2000);

byjus.findElement(By.xpath("//*[@id=\"top-navbar-collapse\"]/ul/li[5]/
a")).click();

Thread.sleep(2000);

byjus.findElement(By.xpath("//*[@id=\"__pf\"]/div/div/div[3]/div/div[1]/
div[2]/div/div/div/div[1]/div/div/div/div/img")).click();
byjus.findElement(By.xpath("//*[@id=\"__pf\"]/div/div/div/div/div/div/
div/div/div[1]/button[3]")).click();

Thread.sleep(2000);

byjus.findElement(By.xpath("//*[@id=\"product_form_7904283590854\"]/
div/div[2]/div/a")).click();

Thread.sleep(2000);
byjus.findElement(By.xpath("//*[@id=\"product_form_7904283590854\"]/
div[1]/div[2]/div/div/div/button")).click();

Thread.sleep(2000);

//byjus.findElement(By.xpath("//*[@id=\"CartDrawer\"]/div[2]/div[2]/
div[2]/div/button")).click();

//

// 8. Youtube

package packageTest;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

@SuppressWarnings("unused")
public class YoutubeTest {

public static void main(String[] args) throws InterruptedException {


// TODO Auto-generated method stub

System.getProperty("Webdriver.chromeDriver","C:\\Users\\91852\\Downloads\\
chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

WebDriver youtube = new ChromeDriver();

youtube.get("https://www.youtube.com");
youtube.manage().window().maximize();

//Delay time for 2 seconds (use fix called surround with try/catch) this fixes the
delay error

Thread.sleep(2000);

youtube.findElement(By.name("search_query")).sendKeys("Ingage technologies");
youtube.findElement(By.xpath("//*[@id=\"search-icon-legacy\"]/yt-icon/yt-icon-
shape/icon-shape/div")).click();

//Delay time for 3 seconds

Thread.sleep(3000);
youtube.findElement(By.linkText("InGage Technologies Pvt Ltd")).click();

}
//

// 9. MakeMyTrip

package Testing1;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FlightTest {

public static void main(String[] args)


{

System.getProperty("webdriver.chrome.driver","D:\\chromedriver-win64\\
chromedriver-win64\\chromedriver.exe");
WebDriver driver1= new ChromeDriver();

driver1.get("https://www.makemytrip.com/");
driver1.manage().window().maximize();
// TODO Auto-generated method stub

driver1.findElement(By.id("fromCity")).sendKeys("Mumbai,India"+Keys.ENTER);
driver1.findElement(By.xpath("//*[@id=\"react-autowhatever-1-section-0-item-
0\"]/div/div[1]/p[1]")).click();
driver1.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
driver1.findElement(By.id("toCity")).sendKeys("New Delhi,India"+Keys.ENTER);
driver1.findElement(By.xpath("//*[@id=\"react-autowhatever-1-section-0-item-
1\"]/div/div[1]/p[1]")).click();
driver1.findElement(By.id("departure")).sendKeys("10 Jan'24"+Keys.ENTER);
// driver1.findElement(By.xpath("//*[@id=\"root\"]/div/div[2]/div/div/div/
div[2]/div[1]/div[3]/div[1]/div/div/div/div[2]/div/div[2]/div[1]")).click();
driver1.findElement(By.xpath("//*[@id=\"root\"]/div/div[2]/div/div/div/
div[2]/div[1]/div[3]/div[1]/div/div/div/div[2]/div/div[2]/div[2]")).click();

driver1.findElement(By.xpath("//*[@id=\"root\"]/div/div[2]/div/div/div/
div[2]/p/a")).click();

}
// Click on the search button
// searchButton.click();

// Close the browser


// driver1.quit();

You might also like