38. Create And Run First Webdriver Script With Eclipse

Run First Webdriver Script

You need to install webdriver with eclipse to run your script in webdriver. After installation of webdriver software testing tool, You need to write a java code in eclipse for your test case of software web application. Let me give you one simple example of creating simple webdriver script for software web application. First of all you need to create the package called "Testing_Pack" under your project and then create new class file 'mytestclass.java' under that package. Now copy-paste bellow given code In your 'mytestclass.java' file.

package Testing_Pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class mytestclass { public static void main(String[] args)
{
            WebDriver driver = new FirefoxDriver();
            driver.get("http://only-testing-blog.blogspot.in");
            String i = driver.getCurrentUrl(); System.out.println(i); driver.close();
            }
}
Now you are ready to run your script from Run menu as shown bellow



Script Explanation

Above script will 
  • open Firefox browser. 
  • Then driver.get syntax will open 'http://only-testing-blog.blogspot.in/' software application in firefox browser.
  • Then driver.getCurrentUrl() will get the current page URL and it will be stored in variable 'i'. You can do same thing using "storeLocation" command in selenium IDE
  • And at last, it will print value of variable in console as shown bellow.


No comments:

Post a Comment