lundi 11 juillet 2016

Refactoring using decorators to reduce code volume

i've recently switch to a new project and all our selenium tests are written in Python. I was wondering if i can reduce the code volume by using decorators

what we got right now is :

class BasePage(object):
    view_button = ".//a[text()='View']"
    create_button = ".//a[text()='Create']"
    #some code here

class BaseTestCase(unittest.TestCase):
    setUpclass(cls):
    #code here

    def find(cls,xpath):
        return cls.driver.find_element_by_xpath(xpath)


class SomeTest(BaseTestCase):
    def test_00_something(self):
        self.find(self.view_button).click()

I'm thinking is there a way to minimize that wholeself.find(self.view_button).click() into something like click.view_button

I heard it could be done using decorators, but being a Java person I had little success with it.

Aucun commentaire:

Enregistrer un commentaire