1

I have some problem with Jenkins and selenium. I try to run this code on Jenkins:

from selenium import webdriver
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800,800))
display.start()
browser = webdriver.Chrome('/home/andrey/Downloads/chromedriver')
browser.get('http://www.google.com/')

try:
   browser.find_element_by_id('gbw')
   print ("Test Pass: ID found")
   browser.find_element_by_id('lga')
   print ("Test Pass: ID found")

except Exception as e:
   print("Exception found",format(e))

So on Jenkins this test pass. But if I do some change in code, Jenkins can't catch exception.

andrew
  • 51
  • 7
  • Maybe it is not a jenkins issue.Locally do you have any exception?Investigate the difference between local an jenkins environments, also check for other errors in jenkins before the try, or maybe you are missing catch block. – lauda Sep 27 '16 at 13:54
  • I have exception when I change my code, and I see exception on jenkins, but jenkins still pass the test instead fail. – andrew Sep 27 '16 at 14:01
  • Add the exception from jenkins if possible.Try a run with except removed, maybe the scripts catches the exception and jenkins sees the results as OK. – lauda Sep 27 '16 at 14:11

1 Answers1

0

I believe this is because you are handling the exception in your code. When there is any exception, you are just printing it. This way the calling application which is Jenkins in your case would not get that exception. You should raise the exception back to the calling application. Alternately, you can raise a custom exception as well to provide more details to the calling application.

Some best practices on catching and raising custom exceptions in python are here

Patz
  • 294
  • 4
  • 18