Python Selenium fails to run in Azure pipeline

maybe somebody can help me here because I am going totally crazy and honestly I have no clue about what I am doing wrong.

I have a python selenium code, long story short, the first step for this selenium, is to open a login webpage and pass the username and password to login.

As the username and password are private, I did use argparse so I can inject those value from the command line in the pipeline.

The selenium script looks as follow:

parser = argparse.ArgumentParser()
parser.add_argument("--USERNAMEOT", type=str)
parser.add_argument("--PASSWORDOT", type=str)
option = parser.parse_args()
USERNAMEOT = option.USERNAMEOT
PASSWORDOT = option.PASSWORDOT


wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class$='visible-lg'] input#signInFormUsername"))).send_keys(USERNAMEOT)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class$='visible-lg'] input#signInFormPassword"))).send_keys(PASSWORDOT)

in my local computer if I go to the terminal and run the code:

python script.py --USERNAMEOT username --PASSWORDOT password

Selenium starts, opens the page and input the username and password. Beautiful, so far everything as expected to be.

Now I wanted to implement the same login in azure pipeline so I can automate this process without having to do it manually every time.

so I start configuring the pipeline as follow

trigger: none

variables:
  vmImageName: 'ubuntu-latest'

stages:
  - stage:
    jobs:
      - job: Test1
        steps:
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'
              addToPath: true
          - script: |
              python -m pip install --upgrade pip
              pip install selenium
              printenv
          - task: Pythonscript@0
            inputs:
              scriptSource: 'filePath'
              scriptPath: './script.py'
              arguments: --USERNAMEOT $(USERNAMEOT) --PASSWORDOT $(PASSWORDOT)

      - job: Test2
        dependsOn: Test1
        steps:
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '3.x'
              addToPath: true
          - script: |
              python -m pip install --upgrade pip
              pip install selenium
          - task: Pythonscript@0
            inputs:
              scriptSource: 'filePath'
              scriptPath: './script1.py'

I set the arguments in the selenium jobs, and configured those values in azure pipeline variables tab.

When the pipeline triggers, thanks to the printing I can see the env variable set correctly.

In the job itself, it shows that the arguments has been passed correctly

/opt/hostedtoolcache/Python/3.9.5/x64/bin/python /home/vsts/work/1/s/script.py --USERNAMEOT username --PASSWORDOT 'password'

But after 30secs the code fails with the following error:

Traceback (most recent call last):
  File "/home/vsts/work/1/s/script.py", line 47, in <module>
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[class$='visible-lg'] input#signInFormUsername"))).send_keys(USERNAMEOT)
  File "/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

This happens because it can't locate the username I suppose, but locally I have the exact same configuration and it run just fine. Can please anyone shade some light on this issue because I have no idea where to look anymore.



Read more here: https://stackoverflow.com/questions/68483440/python-selenium-fails-to-run-in-azure-pipeline

Content Attribution

This content was originally published by Nayden Van at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: