Java builds UI automatic test environment
Download JDK8
www.cnblogs.com/thloveyl/p/…
Configuring the Java Environment
1. Decompress the Jdk package
2. Configure environment variables
Computer -> Properties -> Advanced -> Environment Variables -> System Variables ->Path
3. Add the bin directory in the root directory, lib directory, and bin directory in the JRE directory (recently I found that just add the bin directory to the Path)
{% asset_img 2.PNG %}
Note: all are the absolute path address under the directory, I here on disk E.
4. Enter Java, javac, or java-version
Download the selenium server
Selenium official website Selenium Jar package
Install the Chrome driver of the required version
Click to download ChromeDriver
IDEA Imports the JAR package
File->Project Settings->Modules->Dependencies->’+’->JARS…
Click OK -> jar ->applay-> OK
The instance
package com.smeoa.UI;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class DemoChromeDriver
{
public static void main(String[] args) throws Exception
{
// Set the browser driver properties and values.
System.setProperty("webdriver.chrome.driver"."D:\\Driver\\chromedriver.exe");
// Cancel the chrome info bar that is being controlled by automatic testing software
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
// Instantiate the Driver object
WebDriver driver = new ChromeDriver(options);
Enter https://www.baidu.com in the URL bar
driver.get("http://www.baidu.com");
//xpath element location: input field,sendKeys input Java
driver.findElement(By.xpath("/html//input[@id='kw']")).sendKeys("github");
// Click baidu
driver.findElement(By.xpath("/html//input[@id='su']")).click();
Thread.sleep(100);
// Close the browserdriver.close(); }}Copy the code