NexGenration

Selenium LEX 2

Dec 3rd, 2021
1,030
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.test;
  2. import java.util.concurrent.TimeUnit;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.WebElement;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10. import org.openqa.selenium.support.ui.Select;
  11. public class Demo009_WebPrompts {
  12.     WebDriver driver;
  13.     String url = "http://localhost:8080/PackAndGo_v2/index.html";
  14.  
  15.     @Before
  16.     public void setUp() {
  17.         //Set the key/value property according to the browser you are using.
  18.         System.setProperty("webdriver.gecko.driver",driverPath+"geckodriver.exe");
  19.                  
  20.         //Open browser instance
  21.         driver = new FirefoxDriver();
  22.                        
  23.         //Open the AUT
  24.         driver.get(url);
  25.        
  26.         //Declare an implicit wait which is bounded to WebDriver instance
  27.         driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
  28.     }
  29.  
  30.     @Test
  31.     public void test() throws InterruptedException {
  32.         //Click on Login
  33.         driver.findElement(By.xpath("//*[@id=\"myNavbar\"]/ul/li[4]/a")).click();      
  34.            
  35.         Thread.sleep(2000);
  36.         //Enter the username
  37.         driver.findElement(By.id("usernameLogin")).sendKeys("pgGru");
  38.            
  39.         //Enter the password
  40.         driver.findElement(By.id("passwordLogin")).sendKeys("freezeray");
  41.            
  42.         //Click on Login button
  43.         driver.findElement(By.id("login")).click();
  44.        
  45.         //Find the From dropdown list and store it as a WebElement
  46.         WebElement fromsrc = driver.findElement(By.id("fromDD"));
  47.        
  48.         //Pass the reference variable for fromsrc as a parameter for the Select class
  49.         Select selectFrom = new Select(fromsrc);
  50.        
  51.         //Use the select reference variable for selecting any option using index/value/visible text approach
  52.         selectFrom.selectByIndex(1);
  53.        
  54.         //Find the From dropdown list and store it as a WebElement
  55.         WebElement toDest = driver.findElement(By.id("toDD"));
  56.                
  57.         //Pass the reference variable for toDest as a parameter for the Select class
  58.         Select selectTo = new Select(toDest);
  59.        
  60.         //Use the select reference variable for selecting any option using index/value/visible text approach
  61.         selectTo.selectByValue("Hyderabad");
  62.        
  63.         //click on Search Buses button
  64.         driver.findElement(By.id("searchBus")).click();
  65.        
  66.         //Select the Radio button Search Bus corresponding to BNGHYD2200
  67.         driver.findElement(By.id("radio3")).click();
  68.  
  69.         //Select the Proceed to Booking button
  70.         driver.findElement(By.id("book")).click();
  71.        
  72.         //Enter the No. of Passenger as 10
  73.         driver.findElement(By.id("counter")).sendKeys("10");
  74.        
  75.         //Click on Calculate Total Bill
  76.         driver.findElement(By.xpath("//*[@id=\"rowB6\"]/td/p/input")).click();
  77.        
  78.          
  79.         //clear the value from No of Passenger textbox
  80.         driver.findElement(By.id("counter")).clear();
  81.        
  82.         //Enter the value of No of Passenger as 4
  83.         driver.findElement(By.id("counter")).sendKeys("4");
  84.        
  85.         //Click on Calculate Total Bill
  86.         driver.findElement(By.xpath("//*[@id=\"rowB6\"]/td/p/input")).click();
  87.        
  88.         //Click on ConfirmBooking
  89.         driver.findElement(By.id("confirmBooking")).click();
  90.        
  91.         //Accept the alert box
  92.         driver.switchTo().alert().accept();    
  93.        
  94.         Thread.sleep(2000);
  95.        
  96.         //Click on logout link
  97.         driver.findElement(By.linkText("LogOut")).click();
  98.                
  99.     }
  100.  
  101.     @After
  102.     public void tearDown() {
  103.          //Close the browser
  104.          driver.close();
  105.     }
  106. }
  107.  
RAW Paste Data