问题尝试在Jenkins上运行Robot Framework脚本

huangapple go评论67阅读模式
英文:

Issue trying to run robotframework script on Jenkins

问题

最近我在尝试从Jenkins运行一个任务时遇到了一个问题,该任务只是运行一个.robot文件。我一直在尝试不同的选项,这些选项来自其他曾遇到类似问题的同事在StackOverflow上的解决方案,但是我无法正确运行脚本。

请让我展示给您我正在做的事情,我的脚本和Jenkins设置,这样您就能更好地理解我的问题。

我有这个.robot文件:

*** Settings ***
Documentation   Basic Test
Library    SeleniumLibrary

*** Variables ***
#${result}    /opt/google/chrome/chrome
${Browser}    chrome
${options}    binary_location = '/opt/google/chrome/chrome'

*** Test Cases *** 
Abrir web Pangea
    Open Browser    url=https://www.google.com/    browser=${Browser}   options=${options}
    Close All Browsers

而我尝试将其作为Jenkins的简单任务运行,使用以下简单的构建步骤:

robot --outputdir results --nostatusrc Test/basic_2.robot

但每次控制台输出都显示以下消息:

[Robot_QA_Executions] $ /bin/sh -xe /tmp/jenkins3290544249294601087.sh
+ robot --outputdir results --nostatusrc Test/basic_2.robot
==============================================================================
Basic 2 :: Basic Test                                                         
==============================================================================
Abrir web Pangea                                                      | FAIL |
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
------------------------------------------------------------------------------
Basic 2 :: Basic Test                                                 | FAIL |
1 test, 0 passed, 1 failed
==============================================================================

为了确保Chrome的路径和类似的问题,我还创建了这个Python文件:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

# Chrome驱动程序路径
webdriver.ChromeOptions.binary_location = '/opt/google/chrome/chrome'

# 浏览器选项
ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('--headless')

# 创建Chrome浏览器实例
driver = webdriver.Chrome(chrome_options=ChromeOptions)

# 访问Google Spain的网页
driver.get("https://www.google.es")
print("google abierto")
time.sleep(2)
driver.get("https://pangea.es/")
print("pangea abierto")

# 关闭浏览器
time.sleep(10)
driver.quit()
print("fin del test")

并在Jenkins任务中使用以下构建步骤运行它:

#!/usr/bin/env python3	./Test/ejemplo_Python_2.py

Python脚本按预期工作。

请问您能帮助我解决这个问题吗?我已经尝试了不同的选项,如“options”、“binary_location”、“executable_path”等,但都没有成功。:-(

我还双重检查了我是否已经安装了以下内容:

$ /opt/google/chrome/chrome --version
Google Chrome 110.0.5481.177

$ chromedriver --veresion
Starting ChromeDriver 110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481@{#839}) on port 9515

pip (9.0.3)
Pygments (2.14.0)
robotframework (6.0.2)
robotframework-datadriver (1.6.1)
robotframework-pythonlibcore (3.0.0)
robotframework-seleniumlibrary (6.0.0)
selenium (3.141.0)
setuptools (39.2.0)
urllib3 (1.26.14)

我希望能够从Jenkins任务中运行*.robot文件(我的Jenkins位于AWS Linux机器上),并且存储库在GitLab上。

英文:

Recently i'm facing an issue when try to run a task from Jenkins that simply run a .robot file.
I've been searching and trying different options from another colleagues that faced similar issues in StackOverFlow but i can't achive to run the script correctly.

Please let me show you what i'm doing, my scripts and Jenkins setup so you can understand in a better way my problem.

I have this robot file:

*** Settings ***
Documentation   Basic Test
Library    SeleniumLibrary

*** Variables ***
#${result}    /opt/google/chrome/chrome
${Browser}    chrome
${options}    binary_location = '/opt/google/chrome/chrome'

*** Test Cases *** 
Abrir web Pangea
    Open Browser    url=https://www.google.com/    browser=${Browser}   options=${options}
    Close All Browsers

And i'm trying to run it as a Jenkin simple task with this simple build step:

robot --outputdir results --nostatusrc Test/basic_2.robot

But every time the Console Out show me the msg:

[Robot_QA_Executions] $ /bin/sh -xe /tmp/jenkins3290544249294601087.sh
+ robot --outputdir results --nostatusrc Test/basic_2.robot
==============================================================================
Basic 2 :: Basic Test                                                         
==============================================================================
Abrir web Pangea                                                      | FAIL |
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
------------------------------------------------------------------------------
Basic 2 :: Basic Test                                                 | FAIL |
1 test, 0 passed, 1 failed
==============================================================================

To be sure of the Chrome path and this kind of things i also create this Python file:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

# Ruta del controlador de Chrome
webdriver.ChromeOptions.binary_location = '/opt/google/chrome/chrome'

# Opciones para el navegador
ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('--headless')

# Crea una instancia del navegador Chrome
driver = webdriver.Chrome(chrome_options=ChromeOptions)

# Navega a la pagina web de Google Espana
driver.get("https://www.google.es")
print("google abierto")
time.sleep(2)
driver.get("https://pangea.es/")
print("pangea abierto")

# Cierra el navegador
time.sleep(10)
driver.quit()
print("fin del test")

And after run, also from jenkin task with the build Step:

#!/usr/bin/env python3	./Test/ejemplo_Python_2.py

The Python Script works as expected.

Please can you help me to solve this issue? i tried with different optiones like "options","binary_location", "executable_path" etc... with no success. 问题尝试在Jenkins上运行Robot Framework脚本

I also double-check that i have installed:

$ /opt/google/chrome/chrome --version
Google Chrome 110.0.5481.177

$ chromedriver --veresion
Starting ChromeDriver 110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481@{#839}) on port 9515

pip (9.0.3)
Pygments (2.14.0)
robotframework (6.0.2)
robotframework-datadriver (1.6.1)
robotframework-pythonlibcore (3.0.0)
robotframework-seleniumlibrary (6.0.0)
selenium (3.141.0)
setuptools (39.2.0)
urllib3 (1.26.14)

I would like to add more details to my issue.
If i try with

Create Webdriver    Chrome    executable_path=/usr/local/bin/chromedriver 
Go To    https://www.google.com

instead OpenBrowser. Jenkins return the error msg:

WebDriverException: Message: Service /opt/google/chrome/chrome unexpectedly exited. Status code was: 1

I expect to be able to run *.robot files from a Jenkins task (My Jenkins is over a AWS Linux machine) and the repositoty it's on GitLab.

答案1

得分: 0

Right know all it’s working after some changes in the way i send the Options parameter to Chrome.

I’ll let here the code that make my script works just in case other colleagues could have the same issue trying to setup the chrome options

However i don't know why works with these 2 option values: add_argument("--headless"); add_argument("no-sandbox") ...but works.

First way:

*** Settings ***
Documentation test basico
Library SeleniumLibrary

*** Variables ***
${chrome_options} add_argument("--headless"); add_argument("no-sandbox")

*** Test Cases ***
Abrir web Google
Open Browser https://google.es chrome options=${chrome_options}

Second way:

*** Settings ***
Documentation Basic Test
Library SeleniumLibrary

*** Variables ***
${Browser} chrome
${driver_path} /usr/bin/chromedriver
${chrome_options} add_argument("--headless"); add_argument("no-sandbox")

*** Test Cases ***
Abrir web Google
Open Browser url=https://google.es/ browser=${Browser}  
options=${chrome_options} #executable_path=${driver_path}

Both ways works fine.

Best regards!

英文:

Right know all it’s working after some changes in the way i send the Options parameter to Chrome.

I’ll let here the code that make my script works just in case other colleagues could have the same issue trying to setup the chrome options

However i don't know why works with these 2 option values: add_argument("--headless"); add_argument("no-sandbox") ...but works.

First way:

*** Settings ***
Documentation test basico
Library SeleniumLibrary

*** Variables ***
${chrome_options} add_argument(“–headless”); add_argument(“no-sandbox”)

*** Test Cases ***
Abrir web Google
Open Browser https://google.es chrome options=${chrome_options}

Second way:

*** Settings ***
Documentation Basic Test
Library SeleniumLibrary

*** Variables ***
${Browser} chrome
${driver_path} /usr/bin/chromedriver
${chrome_options} add_argument(“–headless”); add_argument(“no-sandbox”)

*** Test Cases ***
Abrir web Google
Open Browser url=https://google.es/ browser=${Browser}  
options=${chrome_options} #executable_path=${driver_path}

Both ways works fine.

Best regards!

huangapple
  • 本文由 发表于 2023年3月3日 23:00:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628669.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定