优化高亮显示可以在配置文件sys_config.properties中关闭

This commit is contained in:
seagull 2019-12-02 11:47:33 +08:00
parent 20c7504db1
commit 7bbb3a7a4e
2 changed files with 15 additions and 4 deletions

View File

@ -27,3 +27,6 @@ jenkins.url=http://localhost
jenkins.username=test
#jenkinsÃÜÂë
jenkins.password=test1
#==================Web Driver配置========================
#是否高亮显示 true打开 false关闭
webdriver.highlight=false

View File

@ -2,6 +2,7 @@ package luckyclient.execution.webdriver;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.JavascriptExecutor;
@ -11,7 +12,9 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.Augmenter;
import cn.hutool.core.util.BooleanUtil;
import luckyclient.utils.LogUtil;
import luckyclient.utils.SysConfig;
/**
* =================================================================
@ -58,9 +61,14 @@ public class BaseWebDrive {
* @date 2019Äê9ÔÂ6ÈÕ
*/
public static void highLightElement(WebDriver driver, WebElement element){
JavascriptExecutor js = (JavascriptExecutor) driver;
/*调用js将传入参数的页面元素对象的背景颜色和边框颜色分别设定为黄色和红色*/
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "background: yellow; border:2px solid red;");
Properties properties = SysConfig.getConfiguration();
Boolean highLight = BooleanUtil.toBoolean(properties.getProperty("webdriver.highlight"));
if(highLight){
JavascriptExecutor js = (JavascriptExecutor) driver;
/*调用js将传入参数的页面元素对象的背景颜色和边框颜色分别设定为黄色和红色*/
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "background: yellow; border:2px solid red;");
}
}
}