问题描述
我一直试图在Gitlab CI管道中运行ZAP,但是没有运气。即使它在ChromeDriver上的本地计算机上运行良好,当我尝试在Gitlab Shared Runner上运行时与Remote WebDriver进行交互时,我似乎也无法通过执行driver.get(“ http:// localhost:8080” );
不过从gitlab日志中,我可以看到它说: ZAP守护程序作为gitlab-ci.yml文件中给出的命令的一部分启动后,ZAP现在正在localhost:8080上侦听
感谢任何帮助,以了解我在这里做错了什么。
请在下面找到我用于运行测试的测试代码和gitlab ci yml文件。
测试代码:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--ignore- certificate-errors");
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080").setSslProxy("localhost:8080");
WebDriverManager.chromedriver().setup();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY,proxy);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
capabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptions);
WebDriver driver = new RemoteWebDriver(new URL("http://selenium_chrome:4444/wd/hub"),chromeOptions);
driver.get("http://localhost:8080");
Thread.sleep(10000);
String zapheadingText = driver.getTitle();
Assert.assertEquals(zapheadingText,"ZAP API UI");
GitLab CI Yml文件:
图片:maven:latest 变量: MAVEN_OPTS:“-Dmaven.repo.local = .m2 /存储库” 快取: 路径: -.m2 /存储库/ -目标/ 阶段:
- 测试 安全性测试: 阶段:测试 脚本:
解决方法
在ZAP中,我们使用Chrome选项import numpy as np
import cv2
img = cv2.imread(r'/home/pavithra/Downloads/pic.jpeg')
hsvFrame = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
# Set range for red color and
red_lower = np.array([136,86,86],np.uint8)
red_upper = np.array([239,12,50],np.uint8)
red_mask = cv2.inRange(hsvFrame,red_lower,red_upper)
green_lower = np.array([25,52,72],np.uint8)
green_upper = np.array([102,255,255],np.uint8)
green_mask = cv2.inRange(hsvFrame,green_lower,green_upper)
blue_lower = np.array([94,80,2],np.uint8)
blue_upper = np.array([120,np.uint8)
blue_mask = cv2.inRange(hsvFrame,blue_lower,blue_upper)
kernal = np.ones((5,5),"uint8")
red_mask = cv2.dilate(red_mask,kernal)
res_red = cv2.bitwise_and(img,img,mask = red_mask)
# For green color
green_mask = cv2.dilate(green_mask,kernal)
res_green = cv2.bitwise_and(img,mask = green_mask)
# For blue color
blue_mask = cv2.dilate(blue_mask,kernal)
res_blue = cv2.bitwise_and(img,mask = blue_mask)
# Creating contour to track red color
contours,hierarchy = cv2.findContours(red_mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for pic,contour in enumerate(contours):
area = cv2.contourArea(contour)
if(area > 300):
x,y,w,h = cv2.boundingRect(contour)
img = cv2.rectangle(img,(x,y),(x + w,y + h),(0,0),2)
cv2.putText(img,"Red",cv2.FONT_HERSHEY_SIMPLEX,1.0,2)
contours,hierarchy = cv2.findContours(green_mask,cv2.CHAIN_APPROX_SIMPLE)
for pic,"Green",2)
contours,hierarchy = cv2.findContours(blue_mask,cv2.CHAIN_APPROX_SIMPLE)
for pic,(255,"Blue",2)
resize = cv2.resize(img,(800,480))
cv2.imshow("All clg",resize)
cv2.waitKey(0)
,因此值得尝试一下。仅供参考,代码在https://github.com/zaproxy/zap-extensions/blob/master/addOns/selenium/src/main/java/org/zaproxy/zap/extension/selenium/ExtensionSelenium.java中,因此您可能会发现我们所做的其他事情。