31 – Writing Selenium Test Cases Part-2

Selenium Class 31 – Writing Selenium Test Cases Part-2

Write Test Cases…

Test Case 1: Verify Internal and External Links……
Test Case 2: Verify the Element Existence…
Test Case 3: Verify Customer Registration…..

Test Case 4: Verify Customer Login to gcrShop User Interface

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop User Interface (http://www.gcrit.com/build3/)
iii) Click “login” link
iv) Enter “E-Mail Address”
v) Enter “Password”
vi) Click “Sign In” Button

Input / Test Data:
i) E-Mail Address: divyapriya345a@gmail.com
ii) Password: abcd123

Verification Point:
Verify the Existence of “Logoff” link after Sign In.
………………………………
Selenium WebDriver Test script:

System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“http://www.gcrit.com/build3/”);
driver.findElement(By.linkText(“login”)).click();

driver.findElement(By.name(“email_address”)).sendKeys(“divyapriya345a@gmail.com”);
driver.findElement(By.name(“password”)).sendKeys(“abcd123”);
driver.findElement(By.id(“tdb5”)).click();

if (driver.findElement(By.linkText(“Log Off”)).isDisplayed()== true){
System.out.println(“Customer Login is Successful – Passed”);
}
else {
System.out.println(“Customer Login is Unuccessful – Failed”);
}
driver.close();
………………………………
Test Script with exception handling code

System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“http://www.gcrit.com/build3/”);
driver.findElement(By.linkText(“login”)).click();

driver.findElement(By.name(“email_address”)).sendKeys(“divyapriya345a@gmail.com”);
driver.findElement(By.name(“password”)).sendKeys(“abcd123”);
driver.findElement(By.id(“tdb5”)).click();

try{
if (driver.findElement(By.linkText(“Log Off”)).isDisplayed()== true){
System.out.println(“Customer Login is Successful – Passed”);
}
}
catch (NoSuchElementException e){
System.out.println(“Customer Login is Unsuccessful – Failed”);
}
driver.close();


selenium tutorial
Selenium Tutorial for Beginners

Test Case 5: Verify User Registration in a Forum

Test Steps:

i) Launch the Browser
ii) Navigate to gcr Forum (http://www.gcreddy.com/forum/)
iii) Click “Register” Link
iv) Click “I agree to these terms”
v) Enter “Username”
vi) Enter “Email Address”
vii) Enter “Password”
viii) Enter “Confirm password”
ix) Enter “Confirmation code:”
x) Click “Submit” Button

Test Data/Input:
i) Username: vikas123
ii) Email Address: vikas12345@gmail.com
iii) Password: abcd1234
iv) Confirm Password: abcd1234

v) Confirmation code:

Note: In this scenario, Static Test Data is sufficient for first four fields, but for 5th field dynamic test data is required.

“Dynamic submission of Test Data”

Expected Result:
“Your account has been created.”

Verification Point:
Capture the confirmation message and compare with expected result.
………………………………
Note: You can launch any web page directly by providing the page url, otherwise you can use alternate navigation.
Landing Page:
i) gcreddy Forum Registration Page (“http://www.gcreddy.com/forum/ucp.php?mode=register”)

Or
i) gcreddy Forum home( (“http://www.gcreddy.com/forum/)
ii) Registration Page (Click “Register” Link)

Or
i) gcreddy Home page (“http://www.gcreddy.com/)
ii) Forum Home (Click form link (“http://www.gcreddy.com/forum/))
iii) Registration Page (Click “Register” Link(http://www.gcreddy.com/forum/ucp.php?mode=register))
………………………………
Selenium WebDriver Test Script/Test Case:

System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“http://www.gcreddy.com/”);

driver.findElement(By.linkText(“Forum”)).click();
driver.findElement(By.linkText(“Register”)).click();

driver.findElement(By.id(“agreed”)).click();

driver.findElement(By.id(“username”)).sendKeys(“vikasra123”);
driver.findElement(By.id(“email”)).sendKeys(“vikasra12345@gmail.com”);
driver.findElement(By.id(“new_password”)).sendKeys(“abcd1234”);
driver.findElement(By.id(“password_confirm”)).sendKeys(“abcd1234”);

System.out.println(“Enter Captcha”);
Scanner scan = new Scanner(System.in);
String captcha = scan.nextLine();

driver.findElement(By.id(“confirm_code”)).sendKeys(captcha);
driver.findElement(By.id(“submit”)).click();
Thread.sleep(4000);

String message= driver.findElement(By.cssSelector(“#message > div > p”)).getText();
//System.out.println(message);

if (message.contains(“Your account has been created.”)){
System.out.println(“User Registration is Successful – Passed”);
}
else
{
System.out.println(“User Registration is Unsuccessful – Failed”);
}
driver.close();
}
}
………………………………