3

Programing is a new thing for me and probably I am missing something obvious.

I would like to create a separate file and class for setup my webdriver for Appium tests, but I got errors like:

in test_login main_page = MainPage(self.driver)
AttributeError: 'test_Login_iOS' object has no attribute 'driver'

Currently I have two files: one with test case and other with methods for test steps:

  1. test_Login_iOS.py:

    class test_Login_iOS(unittest.TestCase):

    def setUp(self):

    logging.info("WebDriver request initiated. Waiting for response, this may take a while.")
    
    # choose desired capabilities from desired_capabilities.py
    
    desired_capabilities = DesiredCapabilities.desired_capabilities_for_iOS_iPad
    
    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_capabilities)
    
    self.driver.implicitly_wait(15)  # seconds
    

    def test_login(self):

    logging.info("starting Test Case 1: login into active account")
    welcome_page = WelcomePage(self.driver)
    welcome_page.click_login_button()
    login_page = LoginPage(self.driver)
    

and second file, page_ios.py:

class BasePage(unittest.TestCase):
"""
:type driver: appium.webdriver.Remote
"""

def __init__(self, driver):

    super().__init__()
    self.driver = driver

When I add new test case I have to add to it the same setUp method like in previous test case, so I would like to create a new class "Setup" that could be shared across multiple test cases.

Goal is to move setUp method to separate file and new class.

  • I resolved that problem by adding additional method: `@classmethod def setUpClass(cls): if cls is not SetupTestCase and cls.setUp is not SetupTestCase.setUp: orig_set_up = cls.setUp def set_up_override(self, *args, **kwargs): SetupTestCase.setUp(self) return orig_set_up(self, *args, **kwargs) cls.setUp = set_up_override` – Lukas Lewandowski Mar 01 '17 at 11:21

0 Answers0