【问题标题】:I want to get variable values from jenkins in my python code for desired capabilities我想在我的 python 代码中从 jenkins 获取变量值以获得所需的功能
【发布时间】:2018-12-20 15:57:08
【问题描述】:

我想将 jenkins 所需的功能传递给酱汁实验室

我已经用 python 编写了我的代码

desired_caps = {}
desired_caps['platform'] = os.getenv('platform','SELENIUM_PLATFORM')
desired_caps['browserName'] = os.getenv('browserName','SELENIUM_BROWSER')
desired_caps['version'] = os.getenv('version','SELENIUM_VERSION')
context.browser = webdriver.Remote(
    command_executor='http://USER_NAME:KEY@ondemand.saucelabs.com:80/wd/hub',
    desired_capabilities=desired_caps)

在运行构建时在 jenkins 上出现此错误:

Starting pre-build for Sauce Labs plugin
Finished pre-build for Sauce Labs plugin
$ cmd /c call C:\WINDOWS\TEMP\jenkins6037287030698812464.bat
selenium.common.exceptions.WebDriverException: Message: Misconfigured -- 
Unsupported OS/browser/version/device combo: OS: 'SELENIUM_PLATFORM', 
Browser: 'selenium_browser', Version: 'SELENIUM_VERSION.', Device: 
'unspecified'

Executing before all - creating benemax admin with owner permission to use it 
everywhere
User data: {}
Exception WebDriverException: Message: Misconfigured -- Unsupported 
OS/browser/version/device combo: OS: 'SELENIUM_PLATFORM', Browser: 
'selenium_browser', Version: 'SELENIUM_VERSION.', Device: 'unspecified'

C:\Program Files (x86)\Jenkins\workspace\project>exit 1 
Build step 'Execute Windows batch command' marked build as failure
Starting post-build for Sauce Labs plugin
Updating the custom data field for jobs with Jenkins build info for analytics
Stopped/completed/updated 0 jobs
Finished post-build for Sauce Labs plugin
Starting Sauce Labs test publisher
The Sauce OnDemand plugin is configured, but no session IDs were found in the 
test output.
Finished Sauce Labs test publisher
Finished: FAILURE

【问题讨论】:

    标签: python-3.x selenium jenkins automated-tests saucelabs


    【解决方案1】:

    你似乎用错了os.getEnv

    os.getenv('version','SELENIUM_VERSION') 很可能只是os.getenv('SELENIUM_VERSION')

    函数的第二个参数是默认值,第一个是你要获取的环境变量。 https://docs.python.org/3.7/library/os.html#os.getenv

    现在发生的情况是,您尝试获取名为 version 的环境变量的值,该变量不存在,然后它默认返回文字字符串 'SELENIUM_VERSION'

    【讨论】:

    • 谢谢你能帮我完成报告生成部分。
    猜你喜欢
    • 2018-08-22
    • 2017-09-29
    • 2011-07-29
    • 1970-01-01
    • 2022-06-16
    • 2020-02-21
    • 2018-04-10
    • 1970-01-01
    • 2023-02-01
    相关资源
    最近更新 更多