提交 3243a3a7 authored 作者: 孙洁清's avatar 孙洁清

Merge branch 'master' of git.yfzx.zjtys.com.cn:hct/auto-test

......@@ -87,7 +87,9 @@ public class SeleniumExecutor {
driver.switchTo().window(currentWindow);
while (nonNull(currentUrl)) {
Measure measure = testUrl(currentUrl);
measures.add(measure);
if (nonNull(measure)){
measures.add(measure);
}
currentUrl = urlQueue.poll();
}
currentWindow = windowQueue.poll();
......@@ -221,8 +223,12 @@ public class SeleniumExecutor {
message = "页面超时";
success = false;
log.error("error:存在可操作范围之外的元素");
} catch (WebDriverException e) {
message = "无法访问的地址";
success = false;
log.error("error:无法访问的地址");
} catch (Exception e) {
message = "出现预料之外的异常";
message = "出现预料之外的错误";
success = false;
log.error("error:" + e);
}
......@@ -262,8 +268,12 @@ public class SeleniumExecutor {
message = "页面超时";
success = false;
log.error("error:存在可操作范围之外的元素");
} catch (WebDriverException e) {
message = "无法访问的地址";
success = false;
log.error("error:无法访问的地址");
} catch (Exception e) {
message = "出现预料之外的异常";
message = "出现预料之外的错误";
success = false;
log.error("error:" + e);
}
......
package com.zjty.autotest;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zjty.autotest.pojo.report.Measure;
import com.zjty.autotest.pojo.report.Report;
import com.zjty.autotest.pojo.test.Input;
......@@ -9,20 +8,14 @@ import com.zjty.autotest.pojo.test.Project;
import com.zjty.autotest.service.impl.SeleniumExecutor;
import com.zjty.autotest.util.WebDriverUtil;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.boot.jaxb.SourceType;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.List;
@Slf4j
@SpringBootTest
......@@ -33,11 +26,27 @@ class AutotestApplicationTests {
@Test
public void execute() throws InterruptedException {
String url = "file:///C:/code/errorTest.html";
// String url = "https://bbs.colg.cn/forum-171-1.html";
test1(url);
}
private void test1(String url){
WebDriver driver = WebDriverUtil.getWebDriver("firefox");
driver.get(url);
for (String s : driver.manage().logs().getAvailableLogTypes()) {
System.out.println(s);
}
}
private void test2(String url) {
List<Input> inputs = Lists.newArrayList();
inputs.add(new Input(null, null, null, "caozuoyuan123"));
inputs.add(new Input(null, null, null, "caozuoyuan"));
String url = "http://192.168.1.244:8080/person/#/login";
Project project = new Project(
null,
null,
......@@ -45,37 +54,12 @@ class AutotestApplicationTests {
url,
inputs
);
// String url2 = "file:///C:/code/wps/index.html";
// WebDriver driver = WebDriverUtil.getWebDriver("firefox");
// driver.manage().timeouts().pageLoadTimeout(4L, TimeUnit.SECONDS);
// driver.get(url);
// Sleeper.SYSTEM_SLEEPER.sleep(Duration.ofSeconds(2));
// String source1 = driver.getPageSource();
// driver.get(url2);
// driver.get(url);
// Sleeper.SYSTEM_SLEEPER.sleep(Duration.ofSeconds(2));
// String source2 = driver.getPageSource();
// System.out.println(Objects.equals(source1,source2));
Report report = seleniumExecutor.execute(project);
for (Measure measure : report.getMeasures()) {
System.out.println(measure);
}
// Document document = Jsoup.parse(driver.getPageSource());
// List<Element> elements = document.getAllElements().stream()
// .filter(element -> element.childrenSize() == 0)
// .collect(Collectors.toList());
// for (Element element : elements) {
// System.out.println("==============================================");
// System.out.println(String.format("tag:%s text:%s attrs:%s",element.tagName(),element.text(),element.attributes()));
// }
}
private Boolean elementMatch(WebElement webElement, Attributes Attributes) {
return Attributes.asList().stream().allMatch(attribute -> Objects.equals(attribute.getValue(), webElement.getAttribute(attribute.getKey())));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论