如何解决如何处理 python 和 selenium POM 框架中的 SSL 证书错误?
我对这一切都很陌生,但我已经制作了一个混合框架(python、selenium、pytest、页面对象模型),用于练习自动化,并使用 SSL 证书以及如何忽略证书错误来解决问题.我正在使用 https://expired.badssl.com 网站对其进行测试
我发现使用的代码是:
options = self.driver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
self.driver.Chrome(chrome_options=options)
我只是不确定它需要去哪里,如果它甚至是要使用的正确代码。 这是我的 conftest.py 文件中的内容:
from selenium import webdriver
import pytest
from selenium.webdriver.chrome import options
@pytest.fixture()
def setup(browser):
if browser == 'chrome':
driver = webdriver.Chrome()
elif browser == 'firefox':
driver = webdriver.Firefox()
else:
driver = webdriver.Chrome()
return driver
# have to include --browser (opyion) otherwise will return error
# added else,if no browser is specified,default to chrome
def pytest_addoption(parser): # this will get the value from the cli/hooks
parser.addoption("--browser")
@pytest.fixture()
def browser(request): # this will return the browser to the setup method
return request.config.getoption("--browser")
####### Pytest HTML reports #######
# hook for adding environment info to html report
def pytest_configure(config):
config._Metadata['Project Name'] = 'Hybrid Framework'
config._Metadata['Module Name'] = 'Customers'
config._Metadata['Tester'] = 'Amar'
# hook for delete/modify environment info to html report
@pytest.mark.optionalhook
def pytest_Metadata(Metadata):
Metadata.pop("JAVA_HOME",None)
Metadata.pop("Plugins",None)
我创建了一个“sslcert_page.py”页面对象类和一个“test_sslcert.py”。我试过在测试文件中包含代码,所以它看起来像这样:
from selenium.webdriver.chrome import options
from selenium.webdriver.chrome.options import Options
from pageObjects.SSLCertificate.sslcert_page import SSLCertHandling
from utilities.readProperties import ReadConfig
class Test_sslcertf:
baseURL = ReadConfig.getApplicationURL()
# logger = LogGen.loggen()
def test_1(self,setup):
# self.logger.info("************* Test_001_Login *************")
self.driver = setup
options = self.driver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
self.driver.Chrome(chrome_options=options)
self.driver.get(self.baseURL)
self.driver.maximize_window()
sleep(5)
self.sslcert = SSLCertHandling
#self.sslcert.ignoreCert()
但是当我在终端中执行测试时它甚至没有加载页面。
希望对此有更多了解的人可以帮助我。代码在没有设置页面对象模型的情况下完成时很好。谢谢!
解决方法
caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['acceptInsecureCerts'] = True
driver = webdriver.Chrome('./chromedriver',desired_capabilities=caps)
driver.get(
"https://untrusted-root.badssl.com/")
您必须使用所需的功能
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。