python - 使用 Python 从 selenium hub 测试自签名域

标签 python selenium selenium-chromedriver gitlab-ci

我有一个带有 selenium 测试的 gitlab ci,当我尝试使用有效证书测试站点时,一切都很完美。但是当我尝试使用自签名证书测试站点时,发生了错误。

gitlab-ci中的要点:

  services:
    - name: ..../selenium/standalone-chrome
      alias: selenium

    - pytest -vvv --driver Remote --capability browserName chrome --capability acceptInsecureCerts true  test.py

和 python 脚本:

class Test():
  def setup_method(self, method):
    self.driver = webdriver.Remote(command_executor='http://selenium:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)
    self.vars = {}
    print(self.driver.__dict__) 
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_(self):
    
    self.driver.get("https://validcertificate") -- in this case everything is OK
    
    self.driver.get("https://selfsignedcertificate/") -- in this case i have got "ERR_CERT_AUTHORITY_INVALID", because no certificate in the hub browser store

我试过了

cap = DesiredCapabilities.CHROME.copy()
cap["acceptInsecureCerts"] = True

desired_capabilities=cap

在这种情况下,validcert 域仍然可以,但是自签名运行到 selenium.common.exceptions.TimeoutException: Message: timeout:)

问题:我在 python scipt 中遗漏了什么?
或者如何为 gitlab 服务设置证书? (我不想创建 docker 镜像)

日志(acceptInsecureCerts 在最后一部分是“True”,当我在脚本中使用“cap[”acceptInsecureCerts“] = True”)

platform linux -- Python 3.9.0, pytest-6.1.2, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python
cachedir: .pytest_cache
driver: Remote
sensitiveurl: .*
metadata: {'Python': '3.9.0', 'Platform': 'Linux-4.15.0-47-generic-x86_64-with-glibc2.28', 'Packages': {'pytest': '6.1.2', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'variables': '1.9.0', 'selenium': '2.0.1', 'metadata': '1.11.0', 'html': '3.0.0', 'base-url': '1.4.2'}, ...... 'Base URL': '', 'Driver': 'Remote', 'Capabilities': {'browserName': 'chrome', 'acceptInsecureCerts': 'true'}, 'Server': 'selenium:4444'}
.
.
.

---------------------------- Captured stdout setup -----------------------------
{'command_executor': <selenium.webdriver.remote.remote_connection.RemoteConnection object at 0x7fbec774ecd0>, '_is_remote': True, 'session_id': 'c7292a0f03ac6ef856af1a9f625b65dc', 'capabilities': {**'acceptInsecureCerts': False,** 'browserName': 'chrome', 'browserVersion': '87.0.4280.66', 'chrome': {'chromedriverVersion': '87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280@{#355})', 'userDataDir': '/tmp/.com.google.Chrome.RcdGFj'}, 'goog:chromeOptions': {'debuggerAddress': 'localhost:34895'}, 'networkConnectionEnabled': False, 'pageLoadStrategy': 'normal', 'platformName': 'linux', 'proxy': {}, 'setWindowRect': True, 'strictFileInteractability': False, 'timeouts': {'implicit': 0, 'pageLoad': 300000, 'script': 30000}, 'unhandledPromptBehavior': 'dismiss and notify', 'webauthn:virtualAuthenticators': True, 'webdriver.remote.sessionid': 'c7292a0f03ac6ef856af1a9f625b65dc'}, 'error_handler': <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7fbec774ef40>, 'w3c': True, '_switch_to': <selenium.webdriver.remote.switch_to.SwitchTo object at 0x7fbec774e430>, '_mobile': <selenium.webdriver.remote.mobile.Mobile object at 0x7fbec774e250>, '_file_detector': <selenium.webdriver.remote.file_detector.LocalFileDetector object at 0x7fbec774eee0>}
----------------------------- Captured stdout call -----------------------------

最佳答案

我认为这可能是您正在寻找的:

options = webdriver.ChromeOptions()
options.add_argument('ignore-certificate-errors')

关于python - 使用 Python 从 selenium hub 测试自签名域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65133325/

相关文章:

python - 如何获得对带有噪声的图像进行二维高斯拟合的正确参数

python reduce问题对象没有属性

c# - 在 Selenium C# 中使用 PageFactory/FindsBy 时如何初始化 SelectElements?

java - Appium 的 implicitlyWait 不起作用

python - session 未创建异常 : Message: Unable to create new service: ChromeDriverService with ChromeDriver and SeleniumGrid through Python

python - TensorFlow 相当于 np.in1d

python - Django/Wagtail - 通过多个父页面优化页面查询集的最有效方法

.net - .NET 中用于编写验收测试的维护最多的最新框架是什么?

java - CreatePlatformSocket() 失败 : Address family not supported by protocol and cannot find chrome binary using WebDriverManager in AWS Lambda

c# - Selenium ChromeDriver C# - 如何发送快捷浏览器