-1

How I can create a function of the login test case in selenium web driver- python and how I can call it in other test cases?

basically I want to call my login test case in other test cases.

1
class LoginTest(unittest.TestCase):
    def test_first(self):
        self.login("username1", "password1")

    def test_second(self):
        self.login("username2", "password2")

    def login(self, username, password):
        ...
0

With pytest, create a fixture for login in conftest.py

In conftest.py file,

@fixture(scope = 'function')
def login(*args):
  <login_code>

In test files,

def test_home_page_icon(login):
    login()
    <test, verification code>

If you are not using pytest,you can import the login function in test file and call the function in test file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.