Java+selenium automated test environment deployment detailed steps (super detailed)?

Step 1: Check the Google version

It is recommended to use the latest version. Enter the place as shown in the figure to view and upgrade the version:
Insert picture description here
If Google cannot update, it may be caused by QQ Computer Manager or 360 software .

1. Upgrade in the computer manager.
2. Download the version you want according to google's chromedriver file .
3. It is recommended to uninstall the latest version and reinstall.

Because we have to download google's chromedriver file according to our own version. We can go to google's chromedriver file to download , this website downloads the version resources you need. Because mine is 87.0.4280.88, so download the version in the red circle.
Insert picture description here
Because of my window system, download the window according to your system version.
1. It does not matter if your Google version is window64 bit, it is compatible.
2. The corresponding version only needs to correspond to the front, and the number after the last decimal point is not the same. For example, 87.0.4280.88, 88 can be different.
Insert picture description here

Step 2: Put the chromedriver.exe file in the bin file of the JDK.

First of all, you have to enter java -version in cmd . If the corresponding version number does not appear, it proves that your environment variables have not been set, and you have to set your jdk environment variables.

1. Check the JDK path.

Enter cmd in java -verbose can view the version of jdk:
as shown:
Insert picture description here
Since prevent people installed multiple versions of jdk and jre , I was one of them, we have other ways to view JDK path. As shown in the figure, click the red circle to get it out.
Insert picture description here
You can see our jdk path from here.
Insert picture description here

2. Then unzip the chromedriver_32 file we just downloaded

Insert picture description here

3. Put the chromedriver.exe file under the bin file in your jdk path:

Insert picture description here

Step 3: implement environment deployment

1. Create a new Java project.

as the picture shows:
Insert picture description here

2. Right-click on the red circle as shown in the figure

Insert picture description here

2. Select the red circle

Insert picture description here

3. Select all jars in the lib file, and then select Open, as shown in the figure.

Insert picture description here
The address of the lib file is as follows, I set 0 points, which can be downloaded immediately:
lia.zip file

4. Then select ok, as shown in the figure.

Insert picture description here

Step 4: Let's create a new Java file for testing.

After creating a new file, enter the code as shown in the figure.
Insert picture description here
code show as below:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Test {
    
    

	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		WebDriver driver=new ChromeDriver();
		driver.get("https://www.baidu.com");
		driver.findElement(By.name("wd")).sendKeys("新梦想测试");
		driver.findElement(By.id("su")).click();
	}

}

Then we look at the effect and click to run the code.
Insert picture description here
We can see that the operation was successful. The system automatically opened Google and entered the search with Baidu:
Insert picture description here
Congratulations, the environment deployment is successful.

Guess you like

Origin blog.csdn.net/qq_45137584/article/details/111367037