我正在使用python和selenium运行headless chrome。对于我的自动测试,我们在非生产环境中进行测试,如果不在您的计算机上安装.crt证书,则无法访问该环境,以便:
Current User>Trusted Root Certificate Authority
在Dockerfile中,我正在安装证书,如下所示:
FROM selenium/standalone-chrome-debug:latest
RUN sudo apt-get update && sudo apt-get install -y python3 python3-pip
RUN sudo apt-get update && sudo pip3 install pytest pytest-html selenium behave allure-behave
COPY . /home
ADD /certs/*.crt /usr/local/share/ca-certificates/
RUN sudo chmod 644 /usr/local/share/ca-certificates/*.crt && sudo apt-get update && sudo update-ca-certificates && sudo apt-get update
为了使无头镀铬能够正常工作,我使用以下镀铬选项参数:
elif data.get('browser') == 'container':
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('add_experimental_option("excludeSwitches",["ignore-certificate-errors"])')
chrome_options.add_argument('window-size=1200x600')
context.driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", chrome_options=chrome_options)
问题: 现在,当我在安装了.crt证书的个人计算机上以无头模式运行测试时,我的测试工作正常。当我尝试在容器中以无头模式运行它时,这些证书被安装在Dockerfile中,我的测试失败,拍摄这个非prod环境的屏幕截图会给我一个空白图像(全白屏)。这意味着容器中的无头铬由于证书问题无法加载站点
如果我尝试拍摄任何其他不需要任何证书的网站的截图,它会按预期工作
我是否需要添加任何其他步骤,以确保.crt证书正确安装在“受信任的根证书颁发机构”中,以便在容器中以无头模式工作
从容器内部:
/usr/local/share/ca-certificates
目录的.crt文件李>
在进一步挖掘之后,我发现证书被复制到容器内的以下目录中(我必须进入容器中的bashshell并对以下步骤进行故障排除):
为了测试证书是否有效,我尝试在非prod环境url(从容器内部)上使用curl,这同样有效。在这一点上,我确信证书在容器中并且正在工作,但是chrome由于某种原因无法使用这些证书
为了解决这个问题,我使用chrome选项向chrome添加了以下功能:
它开始按预期工作。要查看我为实现此功能而添加的所有参数和功能,下面是chrome的完整配置:
相关问题 更多 >
编程相关推荐