提交 29d2eb92 authored 作者: 黄承天's avatar 黄承天

[fix]

增加对输入参数的非空判断
上级 fa8a57cf
...@@ -12,6 +12,7 @@ import com.zjty.autotest.util.JavaScriptUtil; ...@@ -12,6 +12,7 @@ import com.zjty.autotest.util.JavaScriptUtil;
import com.zjty.autotest.util.WebDriverUtil; import com.zjty.autotest.util.WebDriverUtil;
import com.zjty.autotest.websocket.WebSocketServer; import com.zjty.autotest.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.openqa.selenium.*; import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
...@@ -140,12 +141,14 @@ public class SeleniumExecutor { ...@@ -140,12 +141,14 @@ public class SeleniumExecutor {
if (nonNull(params)) { if (nonNull(params)) {
driver.manage().deleteAllCookies(); driver.manage().deleteAllCookies();
for (Param param : params) { for (Param param : params) {
switch (param.getType()) { if (Strings.isNotBlank(param.getName())&&Strings.isNotBlank(param.getValue())){
case COOKIES: switch (param.getType()) {
driver.manage().addCookie(new Cookie(param.getName(), param.getValue())); case COOKIES:
break; driver.manage().addCookie(new Cookie(param.getName(), param.getValue()));
case SESSION_STORAGE: break;
JavaScriptUtil.setItemInSessionStorage(driver, param.getName(), param.getValue()); case SESSION_STORAGE:
JavaScriptUtil.setItemInSessionStorage(driver, param.getName(), param.getValue());
}
} }
} }
} }
......
...@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory; ...@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
public class WebDriverUtil { public class WebDriverUtil {
//
private static final Logger logger = LoggerFactory.getLogger(WebDriverUtil.class); private static final Logger logger = LoggerFactory.getLogger(WebDriverUtil.class);
private static final String WINDOWS = "Windows"; private static final String WINDOWS = "Windows";
...@@ -40,12 +40,12 @@ public class WebDriverUtil { ...@@ -40,12 +40,12 @@ public class WebDriverUtil {
case Browser.FIREFOX: case Browser.FIREFOX:
// /opt/apps/org.mozilla.firefox/files/lib/firefox-esr/firefox-esr // /opt/apps/org.mozilla.firefox/files/lib/firefox-esr/firefox-esr
System.setProperty("webdriver.firefox.driver", WebDriverUtil.FIRE_FOX + executable); System.setProperty("webdriver.firefox.driver", WebDriverUtil.FIRE_FOX + executable);
System.setProperty("webdriver.firefox.bin", "/home/hct/firefox/firefox"); // System.setProperty("webdriver.firefox.bin", "/home/hct/firefox/firefox");
FirefoxOptions firefoxOptions = new FirefoxOptions(); FirefoxOptions firefoxOptions = new FirefoxOptions();
if (headless) { if (headless) {
firefoxOptions.addArguments("--headless"); firefoxOptions.addArguments("--headless");
} }
// firefoxOptions.setBinary("/opt/apps/org.mozilla.firefox/files/lib/firefox-esr/firefox-esr"); firefoxOptions.setBinary("/opt/apps/org.mozilla.firefox/files/lib/firefox-esr/firefox-esr");
return new FirefoxDriver(firefoxOptions); return new FirefoxDriver(firefoxOptions);
case Browser.CHROME: case Browser.CHROME:
System.setProperty("webdriver.chrome.driver", WebDriverUtil.CHROME + executable); System.setProperty("webdriver.chrome.driver", WebDriverUtil.CHROME + executable);
...@@ -80,7 +80,6 @@ public class WebDriverUtil { ...@@ -80,7 +80,6 @@ public class WebDriverUtil {
default: default:
throw new RuntimeException("该浏览器不存在:" + browser); throw new RuntimeException("该浏览器不存在:" + browser);
} }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论