0

I have a Selenium Python test to check a website is working effectively.

I tested this script multiple times on my local computer and it works just fine. But when I run it in Azure DevOps, it fails. Here is the scenario and where it does failenter image description here

When the page loads, the start and end date are shown in this format dd/mm/yyyy, and the button Start Campaign is greyed out until the correct date format is set (as you can see in the screenshot)

My Selenium code:

start_date = date.today()
# start Date
time.sleep(3)
el_start_date = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/div[2]/main/div[3]/div[1]/div[2]/input')))
time.sleep(5)
el_start_date.clear()
el_start_date.send_keys(start_date.day, Keys.ARROW_RIGHT, start_date.month, Keys.TAB * 2)


# End Date

end_date = start_date + timedelta(days=14)
time.sleep(5)
print(end_date)
el_end_date = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/div[2]/main/div[3]/div[1]/div[3]/input')))
el_end_date.clear()
el_end_date.send_keys(end_date.day, end_date.month,end_date.year)

Locally works just fine and it does input the correct date format and I am able to auto click the Start Campaign, but in Azure DevOps pipeline, the script fails at this stage because it can't target the button, which makes me believe that something is going wrong with the date input format.

I tried everything to debug it but nothing works and I don't know how I can at least retrieve the value of those days to understand how to fix this issue.

Can please anyone help me to figure out this problem or how can I solve it and debug it?

K. B.
  • 3,342
  • 3
  • 19
  • 32
Nayden Van
  • 1,133
  • 1
  • 23
  • 70

1 Answers1

1

You can try to have a look at the page source text:

html_source = browser.page_source

Python Selenium accessing HTML source

If you do not have access to the machine you can make a screenshot/video during the execution:

 driver.save_screenshot("screenshot1.png")

Take screenshot of full page with Selenium Python with chromedriver

There could be a browser alert, or the application you are testing can be slower/faster or the machine (Azure DevOps agent) can have different datetime settings, etc.

K. B.
  • 3,342
  • 3
  • 19
  • 32
  • I will try the html source. Regarding the screenshot, I did try that and it works locally, but it doesn't work in azure pipeline because it doesn't save the file – Nayden Van Aug 27 '21 at 19:35
  • If this is the first click in the script maybe you have issue with the interactive session, you can have a look at the tscon command https://learn.microsoft.com/en-us/azure/devops/pipelines/test/ui-testing-considerations?view=azure-devops&tabs=nunit#visible-ui-testing-using-self-hosted-windows-agents – K. B. Aug 27 '21 at 19:50
  • 1
    The button that is not working, is basically the last button of my script, after that click my script will exit closing the driver. – Nayden Van Aug 27 '21 at 23:15
  • Thanks. In order to save the screenshot in Azure you should attach it to the TestContext, for C# and NUnit the code is TestContext.AddTestAttachment() https://learn.microsoft.com/en-us/azure/devops/pipelines/test/ui-testing-considerations?view=azure-devops&tabs=mstest#capture-screenshots – K. B. Aug 28 '21 at 07:08
  • 1
    Thank you so much for you suggestion. The html source made me understand where the issue was. The click button wasn't working because the start date was an empty value, due a Key.Tab that I had configured in the previous step. Thank you so much for your time and help – Nayden Van Aug 28 '21 at 07:14