IRCTC Signup form script using selenium webdriver


Below script is for filling and submitting signup form of IRCTC website(URL  https://www.irctc.co.in/eticketing/loginHome.jsf).

From following script you can learn handling of different locators, wait command. maximise of  window, Handling of  drop down list, radio box.

(For more information please check the commented text in script)


package irctc;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class Signup {

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

  String exePath = "C:\\Users\\abc\\Downloads\\chromedriver_win32//chromedriver.exe";
  System.setProperty("webdriver.chrome.driver", exePath);

  WebDriver driver = new ChromeDriver();
        
  // Redirect it to URL
  driver.get("https://www.irctc.co.in/eticketing/loginHome.jsf");
  
  //Maximize window
  driver.manage().window().maximize();

  // Click on signup
  driver.findElement(By.linkText("Sign up")).click();
  
  // Enter user id
  driver.findElement(By.id("userRegistrationForm:userName")).sendKeys("testingtreasure");
  
  // Enter password
  driver.findElement(By.id("userRegistrationForm:password")).sendKeys("testingtreasure");
  
  // Enter conform password
  driver.findElement(By.id("userRegistrationForm:confpasword")).sendKeys("testingtreasure");
  
  // select security question
  Select sel = new Select(driver.findElement(By.id("userRegistrationForm:securityQ")));
  sel.selectByIndex(2);
  
  // Enter security answer
  driver.findElement(By.id("userRegistrationForm:securityAnswer")).sendKeys("Testing Treasure school");
  
  // Enter first name
  driver.findElement(By.id("userRegistrationForm:firstName")).sendKeys("first name");
  
  // Enter last name
  driver.findElement(By.id("userRegistrationForm:lastName")).sendKeys("last name");
  
  //Select gender 
  WebElement radiobn = driver.findElement(By.id("userRegistrationForm:gender:0"));
  radiobn.click();
  
  // Select Marital Status
  WebElement status = driver.findElement(By.id("userRegistrationForm:maritalStatus:1"));
  status.click();
  
  // Enter  date of birth
  Select sel1 = new Select(driver.findElement(By.id("userRegistrationForm:dobDay")));
  sel1.selectByIndex(8);
  Select sel2 = new Select(driver.findElement(By.id("userRegistrationForm:dobMonth")));
  sel2.selectByIndex(7);
  Select sel3 = new Select(driver.findElement(By.id("userRegistrationForm:dateOfBirth")));
  sel3.selectByValue("1991");
  
  // Enter occupation
  Select sel4 = new Select(driver.findElement(By.id("userRegistrationForm:occupation")));
  sel4.selectByValue("2");
  
  //Enter email id
  driver.findElement(By.id("userRegistrationForm:email")).sendKeys("testing@gmail.com");
  
  //Enter mobile number
  driver.findElement(By.id("userRegistrationForm:mobile")).sendKeys("7676767677");
  
  // Select nationality
  Select sel5 = new Select(driver.findElement(By.id("userRegistrationForm:nationalityId")));
  sel5.selectByValue("94");

  // Enter flat number
  driver.findElement(By.id("userRegistrationForm:address")).sendKeys("11");
  
  // Select country
  Select sel6 = new Select(driver.findElement(By.id("userRegistrationForm:countries")));
  sel6.selectByValue("94");
  
  // Enter  pin code
  driver.findElement(By.id("userRegistrationForm:pincode")).sendKeys("456001");
  
  //Scroll the window
  JavascriptExecutor jse1 = (JavascriptExecutor) driver;
  jse1.executeScript("window.scrollBy(0,100)", "");

  
  Thread.sleep(3000);
  // Enter city name
  driver.findElement(By.id("userRegistrationForm:cityName")).click();
  Thread.sleep(3000);
  Select sel7 = new Select(driver.findElement(By.id("userRegistrationForm:cityName")));
  sel7.selectByValue("Ujjain");
  
  //Select post office
  Thread.sleep(3000);
  Select sel8 = new Select(driver.findElement(By.id("userRegistrationForm:postofficeName")));
  Thread.sleep(6000);
  sel8.selectByValue("Ujjain Daulatganj S.O");
  // Enter landline number
  driver.findElement(By.id("userRegistrationForm:landline")).sendKeys("7676767677");
  // Enter captcha manually , here we have to give wait command for enter captcha manually.
  Thread.sleep(10000);
  
  //Click on signup button
  driver.findElement(By.linkText("  Submit Registration Form>>>")).click();
  

 }

}

No comments:

Post a Comment