SpringBoot整合Selenium
SpringBoot整合Seleniumpackage com.vmware.config;import lombok.Data;import lombok.extern.slf4j.Slf4j;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.
·
SpringBoot整合Selenium
package com.vmware.config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @apiNote SpringBoot整合Selenium
* @author 冰点契约 2022-05-03
*/
@Configuration(proxyBeanMethods = true)
@ConfigurationProperties(prefix = "selenium-config")
@Slf4j
@ConditionalOnClass(value = {
WebDriver.class
})
@Data
public class SeleniumConfig {
//浏览器语言
private String lang;
//驱动路径
private String driverPath;
//窗口是否最大化
private Boolean windowMax;
@Bean(name = {"driver"})
public ChromeDriver chromeDriver() {
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeDriver driver = new ChromeDriver(chromeOptions());
if (windowMax) {
driver.manage().window().maximize();
}
log.info("chrome driver init success!");
return driver;
}
@Bean
public ChromeOptions chromeOptions() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=" + lang);
options.addArguments("ignore-certificate-errors");
return options;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)