lundi 1 juin 2020

Parameterizing fixtures issue

I need to run tests while authorized to the web page under different user accounts(all of them have different permissions). I've created fixtures for that purpose so I can easily login:

@pytest.fixture
def login_user1(selenium, credentials):
    page = LoginPage(selenium)
    page.login(credentials)

@pytest.fixture
def login_user2(selenium, credentials):
    page = LoginPage(selenium)
    page.login(credentials)

Also, I created a fixture that can be parametrized into running tests for multiple users with just calling it once.

@pytest.fixture
def multiple_users(request):
    request.getfixturevalue(request.param)

And final fixture for the test looks like(This version works)

@pytest.mark.parametrize('multiple_users', [pytest.param('login_user1'),
                                            pytest.param('login_user2',marks=pytest.mark.xfail)
                                                ], indirect=True)
@pytest.mark.usefixtures("multiple_users")
def test_user_permission(self, selenium):
   page = HomePage(selenium)
   ......

Now I'm trying to pass a unique value to the test function each time test runs for different users. I tried doing something like this, but it doesn't work.

@pytest.mark.parametrize('multiple_users,value', [(pytest.param('login_user1'), 'value1'),
                                            (pytest.param('login_user2',marks=pytest.mark.xfail), 'value2')
                                                ], indirect=True)
@pytest.mark.usefixtures("multiple_users")
def test_user_permission(self, selenium, value):
   page = HomePage(selenium)
   ......

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire