1

使用 pytest 和 selenium 运行 webui 自动化测试;有一个问题,我的测试似乎在收集阶段实际上正在运行。在这个阶段,我希望 pytest 能够收集测试——而不是运行它们。最终结果是我得到了 6 个测试结果,而我预计是 2 个。现在有趣的是,这 6 个结果只出现在 HTML 报告中;在命令行上,我只得到预期的 2 行输出(但运行这两个测试需要 300 秒,因为测试实际上是多次运行)。

测试/test_datadriven.py

#!/usr/bin/env python
from unittestzero import Assert
from pages.home import Home
from pages.administration import RolesTab
from api.api import ApiTasks
import time
import pytest

from data.datadrv import *

class TestRolesDataDriven(object):
    scenarios = [scenario1,scenario2]

    @pytest.mark.challenge
    def test_datadriven_rbac(self, mozwebqa, org, perm_name, resource, verbs, allowed, disallowed):
        """
Perform a data driven test related to role based access controls.
All parameters are fullfilled by the data.
:param org: Organization Name
:param perm_name: Permission name
:param resource: Resource
:param verbs: A tuple of verbs
:returns: Pass or Fail for the test
"""

        sysapi = ApiTasks(mozwebqa)
        home_page = Home(mozwebqa)
        rolestab = RolesTab(mozwebqa)

        role_name = "role_%s" % (home_page.random_string())
        perm_name = "perm_%s" % (home_page.random_string())
        username = "user%s" % home_page.random_string()
        email = username + "@example.com"
        password = "redhat%s" % (home_page.random_string())

        sysapi.create_org(org)
        sysapi.create_user(username, password, email)

        home_page.login()

        home_page.tabs.click_tab("administration_tab")
        home_page.tabs.click_tab("roles_administration")
        home_page.click_new()
        rolestab.create_new_role(role_name)

        rolestab.click_role_permissions()

        rolestab.role_org(org).click()
        rolestab.click_add_permission()

        rolestab.select_resource_type(resource)
        home_page.click_next()
        for v in verbs:
            home_page.select('verbs', v)
        home_page.click_next()

        rolestab.enter_permission_name(perm_name)
        rolestab.enter_permission_desc('Added by QE test.')
        rolestab.click_permission_done()

        rolestab.click_root_roles()
        rolestab.click_role_users()

        rolestab.role_user(username).add_user()

        home_page.header.click_logout()
        home_page.login(username, password)

        for t in allowed:
            Assert.true(t(home_page))

        for t in disallowed:
            Assert.false(t(home_page))

数据/data.py

###
# DO NOT EDIT HERE
###

def pytest_generate_tests(metafunc):
    """
Parse the data provided in scenarios.
"""
    idlist = []
    argvalues = []
    for scenario in metafunc.cls.scenarios:
        idlist.append(scenario[0])
        items = scenario[1].items()
        argnames = [x[0] for x in items]
        argvalues.append(([x[1] for x in items]))
    metafunc.parametrize(argnames, argvalues, ids=idlist)
###
# EDIT BELOW
# ADD NEW SCENARIOS
###

scenario1 = ('ACME_Manage_Keys', { 'org': 'ACME_Corporation',
                                   'perm_name': 'ManageAcmeCorp',
                                   'resource': 'activation_keys',
                                   'verbs': ('manage_all',),
                                   'allowed': (Base.is_system_tab_visible,
                                               Base.is_new_key_visible,
                                               Base.is_activation_key_name_editable),
                                   'disallowed': (Base.is_dashboard_subs_visible,)})
scenario2 = ('Global_Read_Only', { 'org': 'Global Permissions',
                                   'perm_name': 'ReadOnlyGlobal',
                                   'resource': 'organizations',
                                   'verbs': ('read','create'),
                                   'allowed': (Base.is_organizations_tab_visible,
                                               Base.is_new_organization_visible,
                                               Base.is_new_organization_name_field_editable),
                                   'disallowed': (Base.is_system_tab_visible,
                                                  Base.is_new_key_visible)})

完整源代码可在 github 获得;https://github.com/eanxgeek/katello_challenge

有人知道这里可能发生什么吗?我正在使用 pytest-mozwebqa 插件、pytests 和 selenium。

谢谢!

4

1 回答 1

1

检查您已安装的 pytest-mozwebqa 的版本。如果您安装的版本 < 0.10,那么您必须更新。

pip-python install --upgrade pytest-mozwebqa

由于 pytest-mozwebqa 中的更改数量,我强烈建议您首先在 python virtualenv 中进行测试。

于 2012-06-08T20:47:27.190 回答