Setup for Selenium
Now that Java and Eclipse have been installed, let's set up Selenium.
To do this, launch Eclipse and create a brand-new Java project as seen below:
- Click on File → New → Java Project
- Enter Project name and click on Next.
- Click on Finish.
Now, create a new class as follows:
- Right Click on Src
- above window should pop-up
- Enter class name and check public static void main checkbox.
- Click on Finish.
Although we have set up Java, Eclipse, and built a Java project, we haven't set up Selenium specifically. For instance, if you begin writing code, an error message will appear because the necessary libraries are missing. In order to import these jar files into Eclipse, we must first download a handful of them. Let's download now.
- Visit Downloads | Selenium
- Unzip downloaded file.
- Click on Classpath then click on Add external JARS on right side.
- Click on Apply and Close.
- Similarly import JAR files from "Lib" folder.
- You will see Referenced libraries under project name.
Selenium client libraries are the programming languages we use to develop code, as we have seen in the selenium architecture. Likewise, Java has been installed for it. The browser driver then receives this code in Json format. To make this browser driver interact with the real browser that is already installed on our system, we must now download the browser driver.
- Again, visit Downloads | Selenium
- Scroll down to Browsers
- Click on browsers
- Click on documentation for the browser that you are going to use. Let's say Edge
- Select the stable version for your operating system and download will start.
(Note: If you want to check the edge version on your system, click on 3 dots at top right corner → then click on Help and Feedback → Click on About Microsoft Edge → You will observe Edge version at top) - Unzip downloaded folder.
- Move to eclipse
- Add this code snippet to access webdriver
System.setProperty("webdriver.Edge.driver", "C:/Browserdrivers/msedgedriver.exe");
- Create an object for Edge webdriver using following code snippet.
WebDriver driver = new EdgeDriver();
- Launch browser using following code snippet
driver.get("https://www.youtube.com");
- Click on run and edge browser will open.
- Similarly, you can download other web drivers and run on your system.
So, we are done with selenium setup
Comments
Post a Comment