1. Selenium Installation process & first code to run
Selenium Installation Process
To install selenium in windows and then execute sample code in chrome browser. Follow the below steps.
Step 1: Install JDK from the official website. Select the OS and download the .exe file accordingly.
https://www.oracle.com/java/technologies/downloads/
After java installation first set the system variable. To set the system variable
1.1 Open control panel => System & Security => System
1.3 Set System variables
a) Now copy your java path, where java has been located copy that address.
Inside System, click on new and give a copied java path inside variable value and name can be anything. In my folder path is like "C:\Program Files\Java\jdk-17" after giving the path click on OK. Now you have set the system variable.
b) Now have to set bin path for this to follow,
Copy bin path inside java folder, In my case path, is like "C:\Program Files\Java\jdk-17\bin".
To paste this inside the System, check for Path and edit it, then create New inside path and paste the URL and save it.
Copy bin path inside java folder, In my case path, is like "C:\Program Files\Java\jdk-17\bin".
To paste this inside the System, check for Path and edit it, then create New inside path and paste the URL and save it.
Note: To check Java is properly installed or not check in the command prompt, Search for cmd in windows search, open the terminal and type, java -version. If successfully downloaded then show it version along with some details otherwise shown error. If an error is there then something is wrong with the installation.
Step 2: Install IDE Eclipse, Eclipse cannot work if Java is not installed on your machine so first need to install java first. follow step 1 to download java.
https://www.eclipse.org/downloads/
Step 3: Install Selenium
https://www.selenium.dev/downloads/
Step 3.2 Add Selenium to the project.
Step 3.3 To add selenium we have to add all the jar files that come inside the selenium installation.
Step3.4 Right-click on the project, Go to properties, Click on Java Build Path, Click on libraries as shown in the below picture.
Step 3.4 If you don't have Classpath then you can select module path after that click on "Add External JARS" and start to add files. And If you are seeing Classpath along with module path then click on Classpath after that click on "Add External JARS" and add jars files. See screenshots below to know how to add JAR files.
Select all JAR files that are inside the selenium-java folder and inside the libs folder.
After the files are added then click on "apply and close" button to save those files.Now selenium is connected with your project now to run test cases you need to add web drivers.
Step 4: Install Web Drivers, Check the browser version and then download the suitable driver version accordingly.
https://chromedriver.chromium.org/downloads
Now, Everything is added and connected just need to write and run the code. So below is the first code to test the case. This web driver .exe file location you have to give at the time of coding so place it in the proper directory.
Step 5: Write the first code in selenium and execute it successfully.
Step 5.1 Right-click on the Src folder, hover the cursor on New and click on a class.
Step 5.2 Give class name and checked the box "public static void main(String[] args)" and click on Finish.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Give the path of the web driver .exe file
System.setProperty("webdriver.chrome.driver","C:\\my_chrome_exe_file\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
}
}
Step 5.4 Now click on run as => Select java project and it is successfully open the chrome browser and in the console, the title is printed.









Comments
Post a Comment