32 – Writing Selenium Test Cases Part-3

Selenium Class 32 – Writing Selenium Test Cases Part-3

Writing Test Cases:
1) Verify Internal and External Links in a web site
2) Verify element existence…..
3) Verify Customer Resigitration….
4) Verify Customer Login….

Test Case 5: Verify User Registration in a Forum

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

driver.manage().window().maximize();

driver.get(“https://www.gcreddy.com/forum/”);
driver.findElement(By.linkText(“Register”)).click();

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

driver.findElement(By.id(“username”)).sendKeys(“Nathiya811”);
driver.findElement(By.id(“email”)).sendKeys(“nathiya5214611@gmail.com”);
driver.findElement(By.id(“new_password”)).sendKeys(“abcd321”);
driver.findElement(By.id(“password_confirm”)).sendKeys(“abcd321”);

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

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

try{
String Message = driver.findElement(By.xpath(“//*[@id=’message’]/div/p”)).getText();
//System.out.println(Message);

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

6) Verify “Redirect” Functionality from Admin Interface to User Interface in gcrShop Application

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface
iii) Click “Online Catalog” Link

Verification Point/s
1) Capture the current url and comapre with expected

iii) Enter Username
iv) Enter Password
v) Click “Login” Button
vi) Click “Online Catalog” Link

Verification Point/s
2) Capture the current url and comapre with expected

Expected Result
“http://www.gcrit.com/build3/”

Input/Test Data
Username =”admin”
Password=”admin@123″

Selenium WebDriver Test Steps:

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

driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.linkText(“Online Catalog”)).click();
Thread.sleep(3000);

String url1= driver.getCurrentUrl();
System.out.println(url1);

if (url1.equals(“http://www.gcrit.com/build3/”)){
System.out.println(“Verification 1 (Before Login): Redirecting to User Interface from Admin – Passed”);
}
else{
System.out.println(“Verification 1 (Before Login): Not Redirecting to User Interface from Admin – Failed”);
}

driver.navigate().back();
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);
String url2 = driver.getCurrentUrl();
System.out.println(url2);

if (url2.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(“Admin Login Successful”);
driver.findElement(By.linkText(“Online Catalog”)).click();
}

Thread.sleep(3000);

String url3= driver.getCurrentUrl();
System.out.println(url3);

if (url3.equals(“http://www.gcrit.com/build3/”)){
System.out.println(“Verification 2 (After Login): Redirecting to User Interface from Admin – Passed”);
}
else{
System.out.println(“Verification 2 (After Login): Not Redirecting to User Interface from Admin – Failed”);
}

driver.close();
……………………………..
Assignment to Nathiya

If Login fails in the above Test Script then stop the execution and show that login failed.

selenium tutorial
Selenium Tutorial for Beginners

7) Data Driven Testing for Admin Login in gcrShop Admin Interface by reading test data from a text file.

System.setProperty(“webdriver.chrome.driver”, “F:/chromedriver.exe”);

FileReader file= new FileReader(“C:\Users\admin\Desktop\input.txt”);
BufferedReader br = new BufferedReader(file);

int Count=0;
int Iteration=0;
String line;

while ((line=br.readLine())!=null){
Count = Count+1;

if (Count > 1 ){
Iteration= Iteration+1;

String [] inputData = line.split(“, “, 2);
driver= new ChromeDriver();
driver.manage().window().maximize();

driver.get(“http://www.gcrit.com/build3/admin/”);

driver.findElement(By.name(“username”)).sendKeys(inputData[0]);
driver.findElement(By.name(“password”)).sendKeys(inputData[1]);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);

String url= driver.getCurrentUrl();

if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(Iteration + ” Admin Login is Successful – Passed”);
}
else {
System.out.println(Iteration +” Admin Login is Unsuccessful – Failed”);
}
driver.close();
}
}
br.close();
file.close();
}
}
………………………………………..