RE: Facing problem in running my first test case. I have tried to run Browser Commands ..with the help of the first video tutorial. Please explain all the step how to run correctly Browser Commands command.

Facing problem in running my first test case. I have tried to run Browser Commands ..with the help of  the first video  tutorial. Please explain all the step how to run correctly Browser Commands command.

kkrqa Default Asked on October 10, 2014 in Selenium WebDriver.

Can you please elaborate what problem you are facing.?  Are you getting error or exceptions?
or Unable to run on Ecilipse?

on October 10, 2014.
Add Comment
1 Answers

 

package mypackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
 import org.openqa.selenium.firefox.FirefoxDriver;
public class firsttestCase {
private static WebDriver driver = null;
public static void main(String[] args) throws InterruptedException {
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Find the element that's ID attribute is 'account'(My Account)
 String sTitle = driver.getTitle();
// Storing Title length in Int variable
int iTitleLength = driver.getTitle().length();
// Printing Title name on Console
System.out.println(sTitle);
// Printing Title length on console
System.out.println(iTitleLength);
// Storing URL in String variable
sTitle = driver.getCurrentUrl();
// Storing URL length in Int variable
iTitleLength = driver.getCurrentUrl().length();
// Printing URL on Console
System.out.println(sTitle);
// Printing URL length on console
System.out.println(iTitleLength);
// Refreshing current page
driver.get(driver.getCurrentUrl());
// Storing Page Source in String variable
String sPageSource = driver.getPageSource();
// Storing Page Source length in Int variable
int iPageSourceLength = driver.getPageSource().length();
// Printing Page Source on console
System.out.println(sPageSource);
// Printing Page SOurce length on console
System.out.println(iPageSourceLength);
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
// Find the element that's ID attribute is 'log' (Username)
// Enter Username on the element found by above desc.
driver.findElement(By.id("log")).sendKeys("testuser_1");
// Find the element that's ID attribute is 'pwd' (Password)
// Enter Password on the element found by the above desc.
driver.findElement(By.id("pwd")).sendKeys("Test@123");
// Now submit the form. WebDriver will find the form for us from the element
driver.findElement(By.id("login")).click();
// Print a Log In message to the screen
System.out.println(" Login Successfully, now it is the time to Log Off buddy.");
// Find the element that's ID attribute is 'account_logout' (Log Out)
 Thread.sleep(1000);
driver.findElement (By.xpath("/html/body/div[2]/div/div/header/div[1]/a")).click();
// Close the driver
driver.quit();
}
}

This will give all browser commands practice

Doctor Answered on October 10, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.