簡體   English   中英

使用 Python 從 selenium 集線器測試自簽名域

[英]Test a self-signed domain from selenium hub with Python

我有一個 gitlab ci 和 selenium 測試,當我嘗試使用有效證書測試站點時,一切都很完美。 但是當我嘗試使用自簽名證書測試站點時,發生了錯誤。

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:消息:超時 :)

問:我在 python scipt 中遺漏了什么?
或者如何為 gitlab 服務設置證書? (我不想創建 docker 圖像)

日志(當我在腳本中使用“cap [”acceptInsecureCerts“] = True”時,最后一部分中的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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM