Jenkins Slave имеет Python и SeleniumLibrary, но все еще получает ** ImportError: нет модуля с именем SeleniumLibrary ** - PullRequest
0 голосов
/ 14 июля 2020

Python, а также SeleniumLibrary установлены, о чем свидетельствует pip list, запущенный Jenkins внутри контейнера. Я не могу заставить это работать, и я подозреваю, что это может быть связано с тем, что нужно запускать jenkins с virtualenv или использовать / не использовать --user

Вот файл Jenkins, который я использую:

// Loads ALM Pipeline library
@Library(['sdop-pipeline-library']) _
import hudson.model.*
import jenkins.model.*
import hudson.tasks.test.AbstractTestResultAction

pipeline {
  agent {
    node {
      label 'robotframework'
    }
  }

  parameters {
    choice(name: 'MULE_ENVIRONMENT', choices:"CERT\nCERT4\nTEST", description: 'Choose Environment')
    string(name: 'JIRA_TICKET', defaultValue: 'SAPIM-52', description: 'JIRA Ticket number')
    string(name: 'API_NAME', defaultValue: 'customer-api-services')
    string(name: 'API-VERSION', defaultValue: '1.0.4')
    string(name: 'ASSET_VERSION', defaultValue: '5.0.2')
    string(name: 'LIST_OF_POLICIES', defaultValue: "logging-init-policy-v1.0.4, common-response-headers-policy-v1.0.0, client ID enforcement-v1.0.2, jwt-validation-policy-v1.0.6")
    string(name: 'AUDIENCE', defaultValue: "customer")
  }
  
  options {
        // only keeps last 3 builds and artifacts
        buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3'))
  }

  stages {
    stage("Publish API"){
      steps {
        script {
          withCredentials([usernamePassword(credentialsId: 'mule_anypoint_user', usernameVariable: 'ANYPOINT_USER', passwordVariable: 'ANYPOINT_PASSWORD')]) {
            sh "export http_proxy=http://x317506:RealMadrid808@180.24.136.14:8080 && \
                export https_proxy=http://x317506:RealMadrid808@180.24.136.14:8080 && \
                pip install --upgrade setuptools --user python && \
                pip uninstall robotframework-seleniumlibrary
                pip install --user robotframework-seleniumlibrary
                pip list && \
                robot --variable USERNAME:$ANYPOINT_USER \
                    --variable PASSWORD:$ANYPOINT_PASSWORD \
                    --variable ENVINMT:${params.MULE_ENVIRONMENT} \
                    --variable API_NAME:${params.API_NAME} \
                    --variable API_VERSION:${params.API_VERSION} \
                    --variable ASSET_VERSION:${params.ASSET_VERSION} \
                    --variable LIST_OF_POLICIES:logging-init-policy-v1.0.4 \
                    --variable JIRA_TICKET:${params.JIRA_TICKET} \
                    tasks/publish-api-mule.robot && \
                unset http_proxy && \
                unset https_proxy"
          }
        }
      }
    }
  }
}


Pip List

Package                        Version
------------------------------ ---------
appdirs                        1.4.4
backports.functools-lru-cache  1.6.1
backports.ssl-match-hostname   3.5.0.1
beautifulsoup4                 4.9.1
certifi                        2020.6.20
chardet                        3.0.4
decorator                      3.4.0
ethtool                        0.8
idna                           2.10
iniparse                       0.4
ipaddress                      1.0.16
javapackages                   1.0.0
kitchen                        1.1.1
lxml                           3.2.1
pip                            20.2b1
pycurl                         7.19.0
pygobject                      3.22.0
pygpgme                        0.3
pyinotify                      0.9.4
pyliblzma                      0.5.3
python-dateutil                1.5
python-dmidecode               3.10.13
pyxattr                        0.5.1
requests                       2.24.0
robotframework                 3.2.1
robotframework-seleniumlibrary 4.4.0
selenium                       3.141.0
setuptools                     44.1.1
six                            1.9.0
soupsieve                      1.9.6
subscription-manager           1.21.10
tqdm                           4.47.0
urlgrabber                     3.10
urllib3                        1.25.9
webdrivermanager               0.8.0
yum-metadata-parser            1.1.4

Environment

Операционная система: RHEL 7 Jenkins Slave, работающий в Docker Контейнер как часть Openshift 3.11 платформа

Запуск команды

robot --variable USERNAME:**** --variable PASSWORD:**** --variable ENVINMT:CERT --variable API_NAME:customer-api-services --variable API_VERSION:null --variable ASSET_VERSION:5.0.2 --variable LIST_OF_POLICIES:logging-init-policy-v1.0.4 --variable JIRA_TICKET:SAPIM-52 tasks/publish-api-mule.robot

Сообщения об ошибках и дополнительная информация

[ ERROR ] Error in file '/tmp/workspace/test-1_master/tasks/resource.robot' on line 7: Importing test library 'SeleniumLibrary' failed: ImportError: No module named SeleniumLibrary
Traceback (most recent call last):
  None
PYTHONPATH:
  /usr/local/bin
  /usr/local/lib/python2.7/site-packages/setuptools-7.0-py2.7.egg
  /usr/local/lib/python2.7/site-packages/robotframework-3.2.2.dev1-py2.7.egg
  /usr/local/lib/python27.zip
  /usr/local/lib/python2.7
  /usr/local/lib/python2.7/plat-linux2
  /usr/local/lib/python2.7/lib-tk
  /usr/local/lib/python2.7/lib-old
  /usr/local/lib/python2.7/lib-dynload
  /home/jenkins/.local/lib/python2.7/site-packages
  /usr/local/lib/python2.7/site-packages
==============================================================================
Publish-Api-Mule :: Publish an API in Anypoint API Manager                    
==============================================================================
Publish API in Anypoint Manager                                       | FAIL |
No keyword with name 'Open Browser' found.

Also teardown failed:
No keyword with name 'Close Browser' found.
------------------------------------------------------------------------------
Publish-Api-Mule :: Publish an API in Anypoint API Manager            | FAIL |
1 critical task, 0 passed, 1 failed
1 task total, 0 passed, 1 failed
==============================================================================
Output:  /tmp/workspace/test-1_master/output.xml
Log:     /tmp/workspace/test-1_master/log.html
Report:  /tmp/workspace/test-1_master/report.html
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

Resource.robot

*** Settings ***
Documentation     A resource file with reusable keywords and variables.
...
...               The system specific keywords created here form our own
...               domain specific language. They utilize keywords provided
...               by the imported SeleniumLibrary.
Library           SeleniumLibrary
Library           String

*** Variables ***
@{POLICIES}                 []
${SERVER}                   anypoint.mulesoft.com
${BROWSER}                  Chrome
${DELAY}                    0
${LOGIN URL}                https://${SERVER}/login
${JIRA_API_ID}              -
${JIRA_AUTODISCOVERY_HASH}  -
${API_ID}                   -
${AUTODISCOVERY_HASH}       -

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open

Login Page Should Be Open
    Title Should Be    Anypoint Platform

Go To Login Page
    Go To    ${LOGIN URL}
    Login Page Should Be Open

Input Username
    [Arguments]    ${USERNAME}
    Input Text  //*[@id="appRoot"]/main/div/div/div/div[1]/form/div[1]/div/div/input    ${USERNAME}

Input Password
    [Arguments]    ${PASSWORD}
    Input Text  password    ${PASSWORD}

Submit Credentials
    Click Element    //*[@id="appRoot"]/main/div/div/div/div[1]/form/button

Welcome Page Should Be Open
    Title Should Be    Anypoint Platform

CLick on API Manager
    Wait Until Element Is Enabled     //*[@id="appRoot"]/div/div/section[1]/div/div[2]/div/ol/li[2]/a/div/span[1]
    Click Element    //*[@id="appRoot"]/div/div/section[1]/div/div[2]/div/ol/li[2]/a/div/span[1]

Select Environment
    [Arguments]     ${ENVIRONMENT}
    Wait Until Element Is Enabled     //div[contains(text(),'${ENVIRONMENT}')]
    Click Element    //div[contains(text(),'${ENVIRONMENT}')]

Click on Manage from API Exchange
    Wait Until Element Is Enabled     //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/div[2]/div[1]/div[1]/button/div[2]
    Click Element       //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/div[2]/div[1]/div[1]/button/div[2]
    Wait Until Element Is Enabled   //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/div[2]/div[1]/div[1]/ul/li[1]/a
    Click Element    //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/div[2]/div[1]/div[1]/ul/li[1]/a

Input API to Deploy and Save
    [Arguments]    ${API NAME}
    Set Focus To Element        //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[1]/div/div/div
    Wait Until Element Is Enabled   //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[1]/div/div/div
    Input Text  //*[@id="react-select-2--value"]/div[2]/input      ${API NAME}
    Sleep   2s
    Mouse Down  //*[contains(text(), "${API NAME}")]
    Press Keys  xpath=//body    TAB

Select API Version
    [Arguments]     ${API VERSION}
    Wait Until Element Is Enabled   //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[3]/div/div/div
    Click Element   //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[3]/div/div/div
    Wait Until Element Is Enabled       //*[contains(text(),'${API VERSION}')]
    Click Element        //*[contains(text(),'${API VERSION}')]

Select Asset Version
    [Arguments]     ${ASSET VERSION}
    Wait Until Element Is Enabled       //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[4]/div/div/div/div/span[2]/span
    Click Element       //*[@id="am-get-from-exchange-container"]/div/form/div[1]/div[4]/div/div/div/div/span[2]/span
    Wait Until Element Is Enabled       //*[contains(text(),'${ASSET VERSION}')]
    Click Element        //*[contains(text(),'${ASSET VERSION}')]

Save and Publish API
    Click Element    //*[@id="save-button"]/span
    Wait Until Element Is Enabled   //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/ap-api-version-header/div[1]/div/div[1]/div/div[1]/span

Copy API ID and Autodiscovery hash
    ${API_ID}=  Get Text    //*[@id="contentWrapper"]/ui-view/ui-view/div/div/div/ap-api-version-header/div[1]/div/div[2]/div[2]/div[1]/span[2]
    Set Suite Variable  ${JIRA_API_ID}  ${API_ID}
    Wait Until Element is Enabled   //*[@id="autodicovery-props"]/span/div/button
    ${AUTODISCOVERY_HASH}=  Get Element Attribute   //*[@id="autodicovery-props"]/span/div/button   attribute=data-clipboard-text
    Set Suite Variable  ${JIRA_AUTODISCOVERY_HASH}  ${AUTODISCOVERY_HASH}

Apply Policy
    [Arguments]     ${POLICY_NAME}
    Wait Until Element is Enabled       //*[@id="contentWrapper"]/div/ap-left-sidebar/div/ul[2]/li[3]/a
    Click Element   //*[@id="contentWrapper"]/div/ap-left-sidebar/div/ul[2]/li[3]/a
    Wait Until Element is Enabled   //*[@id="contentWrapper"]/ui-view/ui-view/div/div/ui-view/div/div[3]/div/div[1]/button
    Click Element   //*[@id="contentWrapper"]/ui-view/ui-view/div/div/ui-view/div/div[3]/div/div[1]/button
    Wait Until Element is Enabled   //*[@class="modal-body ap-resource-level-policies ng-scope"]
    ${for_value}=   Get Element Attribute      //label[@title="${POLICY_NAME}"]      for
    Execute Javascript      document.getElementById("${for_value}").click()
    Wait Until Element is Enabled  //button[contains(text(), "Configure Policy")]
    Click Element   //button[contains(text(), "Configure Policy")]
    Wait Until Element is Enabled  //*[@id="contentWrapper"]/ui-view/div/div/div[1]/form
    Click Element   //*[@id="contentWrapper"]/ui-view/div/div/div[1]/form/div[3]/button[2]


Apply Policies
    [Arguments]     ${ALL_POLICIES_COMMA_SEPARATED}
    @{POLICIES}=    Split String       ${ALL_POLICIES_COMMA_SEPARATED}     ,${SPACE} 
    FOR    ${POLICY}    IN    @{POLICIES}
        Apply Policy  ${POLICY}
    END

Share Details in JIRA via Comment
    [Arguments]     ${JIRA NUMBER}
    Go to   https://jira-sdop.us.corp/browse/${JIRA NUMBER}
    Wait Until Element is Enabled   //*[@id="dprAdapters"]
    Select From List By Index   //*[@id="dprAdapters"]  3
    Submit Form
    Wait Until Element is Enabled   footer-comment-button
    Click Element   footer-comment-button
    Wait Until Element Is Enabled   //*[@id="comment"]
    Sleep   1s
    Input Text  //*[@id="comment"]      ${JIRA_API_ID} \n\n ${JIRA_AUTODISCOVERY_HASH}
    Click Element   //*[@id="issue-comment-add-submit"]
...