Bypassing an Assert in Python

27 views
Skip to first unread message

Dan Baldwin

unread,
Aug 22, 2018, 5:15:51 AM8/22/18
to Selenium Users
Hi guys,

Please bear with me as I am still very new to Selenium and Python. I am a software tester and don't have a development background so the below may or may not make complete sense so I apologise in advance...

Essentially I am trying to bypass some of my tests if they fail, but of course output a fail in the log so I can come back and review later, I know normally you wouldn't want to bypass as this could cause problems later down the line but in these scenarios that I have the data "Should" be static, but on occasion may change, so my entire test pack doesn't fail because someone decided to change the data from 1000 to 1001 I would like it to instead just flag this and move on to the next test... How would I go about doing that?

My current code is - 

assert ("1000" in driver.find_element_by_id("EntityContainingData").text

assert("1001" in driver.find_element_by_id("EntityContainingData2").text

So in the above the 1st assert may fail because the data has changed, but the second one didn't as such I would like the tests to all still continue because this is fine.

Stupidly when I started this I didn't know about Unittest or similar so I didn't implement any of the best practices found within this, and currently I don't have the time to go back and re-format the few thousand lines of code to implement this so if this is possible without implementing that that would be brilliant.

Using PyCharm and Firefox (geckodriver).

These are the imports I am using - 

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time
import datetime
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

Thanks!

Dan
Reply all
Reply to author
Forward
0 new messages