相关疑难解决方法(0)

将ssl证书添加到selenium-webdriver

我将硒用于chromeDriver的端到端测试。要测试的网站需要ssl证书。手动打开浏览器时,会弹出一个窗口,供我选择已安装的证书。不同的测试访问不同的URL,并且还需要不同的证书。但是,如果我以无头模式运行测试,则不会弹出窗口。因此,我需要一种以编程方式设置.pem要用于当前测试的证书(例如,设置文件)的方法。

我该如何实现?我尝试设置一个browserMob代理,然后将其配置为selenium中的代理-但是,这似乎没有任何作用...是否有更好的方法?我究竟做错了什么?这是我尝试过的:

PemFileCertificateSource pemFileCertificateSource = new PemFileCertificateSource(
        new File("myCertificate.pem"),
        new File("myPrivateKey.pem"),
        "myPrivateKeyPassword");

ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
        .rootCertificateSource(pemFileCertificateSource)
        .build();

BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.setTrustAllServers(true);
browserMobProxy.setMitmManager(mitmManager);

browserMobProxy.start(8080);


ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setProxy(ClientUtil.createSeleniumProxy(browserMobProxy));

WebDriver webDriver = new ChromeDriver(chromeOptions);

// use the webdriver for tests, e.g. assertEquals("foo", webDriver.findElement(...))
Run Code Online (Sandbox Code Playgroud)

java selenium ssl-certificate selenium-webdriver browsermob-proxy

13
推荐指数
1
解决办法
586
查看次数

ChromeDriver ERR_SSL_PROTOCOL_ERROR尽管--ignore-certificate-errors

我正在尝试使用带有ChromeDriver的硒在本地主机(没有HTTPS)上运行集成测试。

Chrome需要使用https证书,但是根据这个问题,我知道我可以使用arg来绕过它--ignore-certificate-errors

我也增加了自己的功能acceptInsecureCerts,因为这似乎是适当的做法(docs

chromedriver的响应仍然不是我所期望的:

该网站无法提供安全连接,应用发送的响应无效。ERR_SSL_PROTOCOL_ERROR

我的代码如下:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# make options (principally to ignore certificate)
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')

# add acceptInsecureCerts
capabilities = options.to_capabilities()
capabilities['acceptInsecureCerts'] = True

print(capabilities) # see below

driver = webdriver.Remote(
    command_executor=SELENIUM_HUB,
    desired_capabilities=capabilities
)
print(driver.__dict__) # see further below

app_login_url = 'http://app:8000/accounts/login/'

driver.get(app_login_url)
Run Code Online (Sandbox Code Playgroud)

我的能力:

{'acceptInsecureCerts': True,
'browserName': 'chrome',
'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],
                        'extensions': []},
'platform': 'ANY',
'version': ''}
Run Code Online (Sandbox Code Playgroud)

这是我的驱动程序信息,似乎只acceptInsecureCerts考虑了arg:

{'_file_detector': <selenium.webdriver.remote.file_detector.LocalFileDetector object …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-grid selenium-chromedriver

8
推荐指数
1
解决办法
1156
查看次数