-
Selenide 官网: https://selenide.org/documentation.html
-
Selenide Github :https://github.com/selenide/selenide
-
所有selenium 能做的 selenide 都能做,并且更简单
-
官方给出的详细比较:https://github.com/selenide/selenide/wiki/Selenide-vs-Selenium
利用selenide 面去繁琐的配置,直接上代码
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>5.21.0</version>
</dependency>
以下是一个操作实例的部分代码:
public class TestServiceImpl implements TestService {
@Autowired
ConfigProps configProps;
@Override
public void read() {
// 默认报告目录
Configuration.reportsFolder = "test-result/reports";
// 设置chromedriver位置
// System.setProperty("webdriver.chrome.driver", wanFangProps.getChromeDriverPath());
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
desiredCapabilities.setBrowserName(Browsers.CHROME);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments();
// 设置下载路径
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("download.default_directory", configProps.getDownloadsPath());
chromePrefs.put("download.prompt_for_download", false);
chromePrefs.put("disable-popup-blocking", true);
chromeOptions.setExperimentalOption("prefs", chromePrefs);
Configuration.browserCapabilities = chromeOptions;
WebDriverRunner.clearBrowserCache();
// Setting Browser type instead Firefox by default
Configuration.browser = "chrome";
Configuration.timeout = 80000;
wanfang();
}
private void wanfang() {
open("http://med.wanfangdata.com.cn/");
WebDriverRunner.getWebDriver().manage().window().maximize();
$(By.id("loginUrl")).click();
$(By.id("UserName")).setValue(configProps.getUser());
$(By.id("Password")).setValue(configProps.getPass());
String message = "请在确认后输入验证码,等待" + configProps.getSecond() + "秒";
executeJavaScript("alert('" + message + "')");
sleep(configProps.getSecond() * 1000);
$(By.className("btn-login")).click();
$(By.className("input_search0")).setValue(configProps.getSearch());
$(By.className("MedSearchBtn")).click();
int i = 0;
while (i < configProps.getPages()) {
$$(".btn-download").iterator().forEachRemaining(x -> {
log.info(x.getAttribute("href"));
open(x.getAttribute("href"));
sleep(1000);
});
$(By.className("clicknext")).click();
i++;
}
}
了解更多,欢迎私信
网友评论