python 2.7 - Simplifying Long List of `if` Statements -


i have lot of page objects application testing. page object have of elements on page. writing validate_fields method on each page object when tester navigates page, can call validate_fields method verify of items supposed on page in fact on page.

the problem running validate_fields function can really long, , bunch of

if not x.is_displayed():     self.problems.append("the item x missing page") 

with problems being list of problems assert empty @ end of our test.

below code sample, there way simplify this?

def validate_fields(self):     if not self.el_page_header.is_displayed():         self.problems.append("the page header missing")     if not self.el_preferred.is_displayed():         self.problems.append("the preferred check box missing")     if not self.el_address.is_displayed():         self.problems.append("the address 1 field missing")     if not self.el_address_2.is_displayed():         self.problems.append("the address 2 field missing")     if not self.el_address_3_city.is_displayed():         self.problems.append("the address 3 city field missing")     if not self.el_address_4_state.is_displayed():         self.problems.append("the address 4 state field missing")     if not self.el_address_5_zip_code.is_displayed():         self.problems.append("the address 5 zip code field missing")     if not self.el_contact.is_displayed():         self.problems.append("the contact field missing")     if not self.el_phone.is_displayed():         self.problems.append("the phone field missing")     if not self.el_phone_ext.is_displayed():         self.problems.append("the phone extension field missing")     if not self.el_fax.is_displayed():         self.problems.append("the fax number field missing")     ... 

you put widgets along human-readable name list:

def validate_fields(self):     widgets = [(self.el_page_header, "page header"),                (self.el_preferred, "preferred check box"),                 ... , many more... ]     widget, name in widgets:         if not widget.is_displayed():             self.problems.append("the %s missing" % name) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -