I've been doing some digging the past few days, but cannot seem to find this answer anywhere. The closest I came to finding the answer was here and a few other questions and websites that talked about using dictionaries & keys. I just could not figure out how to apply this to my situation.
I'm looking for a way to determine the value of a dictionary key based on certain conditions. It does not have to be done in this way. This is just how I'm attempting to do it. I'm open to doing it differently. I have several objects on a webpage I need to verify, but the location of those objects as well as their values could be based on a platform version. So, for example...
located in modem.py:
modem_locators = {
'serial_port_txt': ["By.XPATH", "//fieldset[2]/legend", "Serial Port"],
}
located in test_file.py:
.
.
from modem import modem_locators
.
.
assertExpectedConditionTrue(driver, modem_locators.get('serial_port_txt')[0], modem_locators.get('serial_port_txt')[1], modem_locators.get('serial_port_txt'[2])
... verifies that "Serial Port" exists at the XPATH location "//fieldset[2]/legend". I'd like to define 'serial_port_txt' like this:
WARNING - PSEUDO CODE!
modem_locators = {
if glob_var.platform == "A" or glob_var.platform == "B":
serial_port_txt': ["By.XPATH", "//fieldset[2]/legend", "Serial Ports"],
elif glob_var.plaform == "C":
'serial_port_txt': ["By.XPATH", "//fieldset[1]/legend", "Serial Ports"],
else:
'serial_port_txt': ["By.XPATH", "//fieldset[1]/legend", "Serial Port"],
'ip_addr': ["By.ID", "ip_address"]
'enable_checkbox': ["By.ID", "my_checkbox"],
}
The 'platform' variable is defined early on. Can this be done? I'm open to creating the variable based on the platform it's specific to, but thought I'd see if this was possible first.
Also, is there a way to get rid of the 'get()' method, or am I pretty much stuck using that if I'm going to use a dictionary? Thanks!
Aucun commentaire:
Enregistrer un commentaire