How to write my first Test Case using Selenium in Eclipse? – User friendly Tech help
We are already finished with the prerequisite for starting with “Selenium”.Now we are taking a step further towards learning “Selenium”.
nYou can also check how to write first program in Eclipse.
n
nRequirement:-Configuring Selenium Webdriver Jar files in Eclipse to write our first Selenium Program.
n
nSolution:-
nStep1:-Adding Jar files to Eclipse
n
nRight Click “Java Project” in Package Explorer ->Build Path ->Configure Build Path
n
Configure Build Path |
n
Select Libraries Tab ->Click Add External JAR’s
n
n
Add External JAR’s |
n
Browse to Selenium JAR files (For DownloadProcess) ->Add the Selenium JAR (We can add source JAR also) , Open the Lib folder to add all the JAR files.
n
Browse the Selenium JAR location |
n
Click OK button to Add all the selected JAR files
n
Adding JAR to Project |
n
nNote :- One’s JAR files are added, we can confirm it, under Reference in Project Explorer
n
Step2:- Writing and Running our first line of Selenium Code.(For running the First Java Program)
nFlow :- Launching the firefox browser -> open the URL -> fetch the Title details.n
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LearnSelenium {
public static void main(String[] args) {
//Creating WebDriver Object
System.out.println("Launching the Browser");
WebDriver driver = new FirefoxDriver();
//Opens the given URL
driver.get("http://www.uftHelp.com");
System.out.println("Fetching the Title");
System.out.println("Please Wait!!");
//Returns the Title of Current Page
String sTitle = driver.getTitle();
System.out.println("My First Selenium Program");
System.out.println("Title is = '"+sTitle+"'" );
//Closing the Browser
driver.close();
}
}
n
Add the above lines of code and Run it to success (CTRL + F11)
n
nResult in Console
n
Console Results |
n
How to run the above code in Google Chrome?