问题描述:

I am using the latest Sauce OnDemand Plugin to get the Desired capabilities for Robot Framework Script.

Because I am selecting multiple OS and Browser combinations, I will get the values stored in SAUCE_ONDEMAND_BROWSERS which is a Json. The Values for JSON should be added to the desired capabilities.

How do I loop through a JSON and assign the values to variables such that the selenium test is run through all selected combinations from the Sauce OnDemand Plugin?

The following works, when I just have a single operating system/browser combination.

${desired_capabilities} build:%{JENKINS_BUILD_NUMBER},name:%{JENKINS_BUILD_NUMBER}, platform:%{SELENIUM_PLATFORM},browserName:%{SELENIUM_BROWSER‌​},version:%{SELENIUM‌​_VERSION},tunnelIden‌​tifier:%{TUNNEL_IDEN‌​TIFIER}

The Sauce plugin has set the following environment variables:

SELENIUM_DRIVER: sauce-ondemand:?os=Linux&browser=chrome&browser-version=latest&username=g246877&access-key=86c9e0cc-4567-46g2-9b6l-ufeyda3621b16

SAUCE_ONDEMAND_BROWSERS: [{"os":"Linux","platform":"LINUX","browser":"chrome","browser-version":"latest","long-name":"Google Chrome","long-version":"latest","url":"sauce-ondemand:?os=Linux&browser=chrome&browser-version=latest&username=g246877&access-key=86c9e0cc-4567-46g2-9b6l-ufeyda3621b16"},{"os":"Linux","platform":"LINUX","browser":"opera","browser-version":"latest","long-name":"Opera","long-version":"latest","url":"sauce-ondemand:?os=Linux&browser=opera&browser-version=latest&username=g246877&access-key=86c9e0cc-4567-46g2-9b6l-ufeyda3621b16"},{"os":"Windows 10","platform":"WIN10","browser":"chrome","browser-version":"latest","long-name":"Google Chrome","long-version":"latest","url":"sauce-ondemand:?os=Windows 10&browser=chrome&browser-version=latest&username=g246877&access-key=86c9e0cc-4567-46g2-9b6l-ufeyda3621b16"},{"os":"Windows 2008","platform":"VISTA","browser":"firefox","browser-version":"latest","long-name":"Firefox","long-version":"latest","url":"sauce-ondemand:?os=Windows 2008&browser=firefox&browser-version=latest&username=g246877&access-key=86c9e0cc-4567-46g2-9b6l-ufeyda3621b16"}]

网友答案:

Figured it out.

SAUCE_ONDEMAND_BROWSERS is json.

Here is what does the magic:

  1. Save the Json as a file
  2. Use the Get Json Value to get the values of each variable.
  3. Use the Set Variable to append each to get the desired capabilities.
  4. Pass it to the Open Browser keyword in the same FOR loop.
相关阅读:
Top