背景
尝试使用python硒进行自动化测试-pytest framework / pycharm IDE
问题-在本地计算机上运行测试时,通过将可执行路径作为本地chrome-path(即chrome-driver)
但是,我需要每天通过Jenkins在浏览器堆栈上远程运行这些测试。所以我添加了用于浏览器堆栈的代码,但是它不起作用
错误消息-当我执行代码时-收到以下错误消息时,任何有助于解决此问题的建议都会很棒。
from selenium import webdriver
import time
import pytest
from ZProjects.AutomationS.Pages.utils import Utils
from ZProjects.AutomationS.Pages.loginPage import loginpageMethods
from ZProjects.AutomationSynapse.Pages.logoutPage import logoutpageMethods, logoutpageLocators
@allure.severity(allure.severity_level.NORMAL)
def test_setup():
global driver
desired_cap = {
'browser': 'Chrome',
'browser_version': '79.0',
'os': 'Windows',
'os_version': '10',
'resolution': '1024x768',
'name': 'Bstack-[Python] Sample Tests'
}
driver = webdriver.Remote(
command_executor='https://jpopiiiiii@hub-cloud.browserstack.com/fg/hub',
desired_capabilities=desired_cap)
# driver = webdriver.Chrome(executable_path=Utils.chromePath) # commented this line
driver.implicitly_wait(10)
driver.maximize_window()
time.sleep(10)
print("Chrome Browser Launched successfully - Setup - Passed")
@allure.severity(allure.severity_level.BLOCKER)
def test_login_1():
driver.get(Utils.url)
login = loginpageMethods(driver)
login.enter_username(Utils.username)
login.enter_password(Utils.password)
login.click_login()
time.sleep(50)
print("User logged in Successfully - Passed")
self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x0000014F3C424DA0>
method = 'POST', url = '/wd/hub/session'
body = '{"capabilities": {"firstMatch": [{}], "alwaysMatch": {}}, "desiredCapabilities": {"browser": "Chrome", "browser_version": "79.0", "os": "Windows", "os_version": "10", "resolution": "1024x768", "name": "Bstack-[Python] Sample Tests"}}'
headers = {'Accept': 'application/json', 'Authorization': 'Basic amVubmlmZXJwYWlzMjozeHN6bml3bXNHcVFRejNqblhvaQ==', 'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'selenium/3.141.0 (python windows)'}
retries = Retry(total=0, connect=None, read=None, redirect=None, status=None)
redirect = False, assert_same_host = False
timeout = <object object at 0x0000014F39E8EDD0>, pool_timeout = None
release_conn = True, chunked = False, body_pos = None
@allure.severity(allure.severity_level.BLOCKER)
def test_login_1():
> driver.get(Utils.url)
E NameError: name 'driver' is not defined
Test_Results_General_Scenarios_Module.py:50: NameError
答案 0 :(得分:0)
您可以通过以下链接查看BrowserStack文档,以在Python中执行测试:https://www.browserstack.com/automate/python#getting-started
此外,按照链接{@ {3}}
中所述配置功能。