Selenium WebDriver Script 2

Test Case for Facebook Registration:
  1. Launch Chrome Browser
  2. Open the URL http://facebook.com
  3. Enter First name abcd
  4. Enter Surname XYZ
  5. Enter email address abcdefgh@gmail.com
  6. re-enter email address abcdefgh@gmail.com
  7. enter password 9756325625
  8. select drop down Day by value 10
  9. select drop down Month by visible Text Apr
  10. select dropdown Year by index 4
  11. click radio button
  12. click Create Account

package com.facebook.register;

import org.testng.annotations.Test;
import utility.Helper;
import org.testng.annotations.BeforeTest;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;

public class FacebookReg {
      WebDriver driver;
      @Test
      public void facebookRegistration() throws InterruptedException {
              driver.get("http://facebook.com");
            String password = "9756325625";
            String emailID="abcdefgh@gmail.com";
            driver.findElement(By.id("u_0_1")).sendKeys("abcd");
            
            //Enter last Name using name locator
            driver.findElement(By.name("lastname")).sendKeys("XYZ");
            
            //Enter Email ID or Mobile number using xapath locator
            driver.findElement(By.xpath(".//*[@id='u_0_6']")).sendKeys(emailID);
            
            
//Re-Enter Email ID or Mobile Number using cssSelector
            driver.findElement(By.cssSelector("#u_0_9")).sendKeys(emailID);
            
            //Enter Password using Xpath locator
            driver.findElement(By.xpath(".//*[@id='u_0_b']")).sendKeys(password);
            
            //selectByValue using Select Class
            Select day = new Select(driver.findElement(By.id("day")));
            day.selectByValue("10");
            System.out.println("Selected Option of Day dropdown");
            List dayOptions = day.getAllSelectedOptions();
            for (int i = 0; i < dayOptions.size(); i++) {
                System.out.println(dayOptions.get(i).getText());
            }
            
            System.out.println("All options of Month Dropdown");
            List allMonthOption = driver.findElements(By.xpath("//select[@id='month']/option"));
            /*
            for (int i = 0; i < allMonthOption.size(); i++) {
                System.out.println("value :" + allMonthOption.get(i).getAttribute("value")  + " Visible Text: " + allMonthOption.get(i).getText());
            }*/

            for (WebElement option : allMonthOption) {
                System.out.println("value :" + option.getAttribute("value")  + " Visible Text: " + option.getText());
            }
            //selectByVisibleText using Select Class
            Select month = new Select(driver.findElement(By.name("birthday_month")));
            month.selectByVisibleText("Apr");
            
            //selectByIndext using Select Class
            Select year = new Select(driver.findElement(By.cssSelector("select[id='year']")));
            year.selectByIndex(4);
            
            Thread.sleep(2000);
            //Click a radio buttom
            driver.findElement(By.id("u_0_i")).click();
            
            Thread.sleep(5000);
            
            driver.findElement(By.id("u_0_f")).click();
            
            Thread.sleep(10000);
      }
      @BeforeTest
      public void beforeTest() {
          driver = Helper.launchBrowser("chrome");
      }

      @AfterTest
      public void afterTest() {
          driver.quit();
      }
}

No comments:

Post a Comment