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.

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):
| improve this answer | |

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

In conftest.py file,

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

In test files,

def test_home_page_icon(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.

| improve this answer | |

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.