Reputation: 413
I have a problem with Zap plugin in Jenkins. Assume I have my selenium script wrriten in java , it will launch a browser and set a proxy automatically. What I need is to launch selenium java code from Jenkins, and use the zap plugin to open the zap proxy and generate report.
The process in Jenkins should be : 1. start ZAP proxy as pre-build, 2. Execute Selenium java code (which will go through the ZAP proxy automatically) 3. ZAP generate report and send back to Jenkins. 4. Shut down ZAP proxy.
My confusion is when I use the zap plugin in Jenkins, there is a starting point URL which is mandatory. But I don't want an active scanning, I only need a passive scanning from what go through the zap proxy by selenium script. Is there a way to walk around it? Any advise on this would be helpful.
Please find my sample selenium java script below:
public class Sample_ZapProgram {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
Proxy proxy = new Proxy();
// proxy.setHttpProxy("localhost:8090");
proxy.setFtpProxy("localhost:8090");
proxy.setSslProxy("localhost:8090");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver","C:\\Users\\Administrator\\workspace\\chromedriver.exe");
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://demo.testfire.net/");
Thread.sleep(15000);
driver.quit();
//tearDown();
}
}
Upvotes: 2
Views: 579
Reputation: 11864
Java sample (sample come from NoraUI POC):
/**
* NoraUi is licensed under the license GNU AFFERO GENERAL PUBLIC LICENSE
*
* @author Nicolas HALLOUIN
* @author Stéphane GRILLON
*/
package com.github.noraui.bot;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.noraui.utils.Utilities.OperatingSystem;
import com.github.noraui.utils.Utilities.SystemArchitecture;
public class FirstSimpleBotWithZAPProxy {
private static final Logger logger = LoggerFactory.getLogger(FirstSimpleBotWithZAPProxy.class);
public static void main(String[] args) throws InterruptedException {
Proxy proxy = new Proxy();
proxy.setAutodetect(false);
proxy.setHttpProxy("http://localhost:8092");
final OperatingSystem currentOperatingSystem = OperatingSystem.getCurrentOperatingSystem();
String pathWebdriver = String.format("src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s", currentOperatingSystem.getOperatingSystemDir(),
SystemArchitecture.getCurrentSystemArchitecture().getSystemArchitectureName(), currentOperatingSystem.getSuffixBinary());
if (!new File(pathWebdriver).setExecutable(true)) {
logger.error("ERROR when change setExecutable on " + pathWebdriver);
}
System.setProperty("webdriver.chrome.driver", pathWebdriver);
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setProxy(proxy);
WebDriver driver = new ChromeDriver(chromeOptions);
for (int i = 0; i < 6; i++) {
driver.get("http://www.google.com/ncr");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("NoraUi");
element.submit();
logger.info(driver.getTitle());
WebElement r = driver.findElement(By.xpath("//*[@id='resultStats']"));
logger.info(r.getText());
}
driver.quit();
}
}
ZAP result:
Upvotes: 1