我试图使用zap设置硒测试,webdriver应该是firefox,端口是8080。但是当打开端口时,端口始终是一个不同的数字。 这是下面的测试,我不知道如何在8080 anfd firefox浏览器端口下打开浏览器,实际上该浏览器确实打开了,但是什么也没出现。
public class Sport {
WebDriver driver;
final static String BASE_URL = "https://web-test.com/";
final static String USERNAME = "test@hotmail.com";
final static String PASSWORD = "tables";
public Sport(WebDriver driver) {
this.driver = driver;
this.driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
this.driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
public void login()throws Exception {
driver.get(BASE_URL);
Header header = new Header();
header.guest_select_login();
Pages.Login login = new Pages.Login();
login.login_with_empty_fields();
login.login_with_invalid_email();
login.email_or_password_incorrect();
login.login_open_and_close();
}
Client zap api可以正常工作并启动,但浏览器似乎无法正确打开端口8080
public class ZapScanTest {
static Logger log = Logger.getLogger(ZapScanTest.class.getName());
private final static String ZAP_PROXYHOST = "127.0.0.1";
private final static int ZAP_PROXYPORT = 8080;
private final static String ZAP_APIKEY = null;
// Change this to the appropriate driver for the OS, alternatives in the
drivers directory
private final static String FIREFOX_DRIVER_PATH = "drivers/geckodriver.exe";
private final static String MEDIUM = "MEDIUM";
private final static String HIGH = "HIGH";
private ScanningProxy zapScanner;
private Spider zapSpider;
private WebDriver driver;
private Sportdec myApp;
private final static String[] policyNames = {"directory-browsing","cross-
site-scripting","sql-injection","path-traversal","remote-file-
inclusion","server-side-include",
"script-active-scan-rules","server-side-code-injection","external-
redirect","crlf-injection"};
int currentScanID;
@Before
public void setup() {
zapScanner = new ZAProxyScanner(ZAP_PROXYHOST,ZAP_PROXYPORT,ZAP_APIKEY);
zapScanner.clear(); //Start a new session
zapSpider = (Spider)zapScanner;
log.info("Created client to ZAP API");
driver = DriverFactory.createProxyDriver ("firefox",createZapProxyConfigurationForWebDriver(), FIREFOX_DRIVER_PATH);
myApp = new Sportdec(driver);
//myApp.registerUser();
}
@After
public void after() {
driver.quit();
}
@Test
public void testSecurityVulnerabilitiesBeforeLogin()throws Exception {
myApp.login();
log.info("Spidering...");
spiderWithZap();
log.info("Spider done.");
setAlertAndAttackStrength();
zapScanner.setEnablePassiveScan(true);
scanWithZap();
List<Alert> alerts = filterAlerts(zapScanner.getAlerts());
logAlerts(alerts);
assertThat(alerts.size(), equalTo(0));
}