A, Linux machine to install google-chrome-stable
1, a software source google-chrome
sudo vim /etc/yum.repos.d/google-chrome.repo
[google-chrome] name=google-chrome baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64 enabled=1 gpgcheck=1 gpgkey=https://dl.google.com/linux/linux_signing_key.pub
2, the installation-dependent [process as suggestive of other missing dependency, up to https://rpmfind.net/linux/rpm2html/search.php query execution rpm package names corresponding to sudo yum install -y mounted to]
sudo yum install https://mirrors.dotsrc.org/fedora-epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm -y sudo yum install Xvfb -y sudo yum install xorg-x11-fonts* -y sudo yum install https://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/l/liberation-fonts-common-2.00.5-6.fc32.noarch.rpm -y sudo yum install https://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/l/liberation-mono-fonts-2.00.5-6.fc32.noarch.rpm -y sudo yum install https: // rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/l/liberation-sans-fonts-2.00.5-6.fc32.noarch.rpm - and sudo yum install https: // rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/l/liberation-serif-fonts-2.00.5-6.fc32.noarch.rpm - and sudo yum install - and https: // rpmfind.net/linux/fedora-secondary/development/rawhide/Everything/ppc64le/os/Packages/l/liberation-fonts-2.00.5-6.fc32.noarch.rpm -and
3, mounting google-chrome-stable
sudo yum install google-chrome-stable -y
Second, prepare the client [webdriver issued to the server with client]
public static WebDriver driver;
/ ** * initialize Driver * @throws Exception * / public void initDriver () throws Exception { String path; File File; String OSNAME = System.getProperty ( "os.name" ) .toLowerCase ();
// do lasting version webdriver of, loaded into memory when the driver initialization, configuration dynamic invocation IF (getClass (). getResource ( "/") == null ) { String chromePath = "the Drivers /." concat (osName.startsWith ( "Windows")? ContextUtils. getContextStr (CHROME_DRIVER_WINDOWS): osName.startsWith ( " mac")? ContextUtils.getContextStr(CHROME_DRIVER_MAC) : ContextUtils.getContextStr(CHROME_DRIVER_LINUX)); path = String.format("%s%starget%s%s", System.getProperty("base.dir"), File.separator, File.separator, chromePath); file = new File(path); } else { String chromePath = "drivers/".concat(osName.startsWith("windows") ? ContextUtils.getContextStr(CHROME_DRIVER_WINDOWS) : osName.startsWith("mac") ? ContextUtils.getContextStr(CHROME_DRIVER_MAC) : ContextUtils.getContextStr(CHROME_DRIVER_LINUX)); path = String.format("%s%s%s", getClass().getResource("/").getPath(), File.separator, chromePath); file = new File(path); if (file.exists() == false) { FileUtils.copyInputStreamToFile(new ClassPathResource(chromePath).getInputStream(), new File(path)); } } if (!osName.startsWith("windows")) { try { Runtime.getRuntime().exec(String.format("chmod 777 %s", path)); } catch (Exception ex) { } } CartierSystemSettings systemSettings = systemSettingsMapper.selectValueByCode(ChromeDriverService.CHROME_DRIVER_WHITELISTED_IPS_PROPERTY); if (null != systemSettings) { System.setProperty(ChromeDriverService.CHROME_DRIVER_WHITELISTED_IPS_PROPERTY, systemSettings.getValue()); } logger.info("webdriver.chrome.driver={}", path); System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, path); ChromeOptions options = getChromeOptions(osName); driver = new ChromeDriver(options); } /** * 对非mac & Windows系统开启隐藏头模式 * @param osName * @return */ public static ChromeOptions getChromeOptions(String osName) { ChromeOptions options = new ChromeOptions(); if (!osName.startsWith("mac") && !osName.startsWith("windows")) { options.addArguments("--headless"); options.addArguments("--disable-gpu"); options.addArguments("--no-sandbox"); } options.addArguments("--verbose"); options.addArguments("window-size=1920x1920"); return options; }