0

我正在尝试使用 ptest-bdd 运行测试。我使用了场景大纲,但变量用户名返回一个名称错误,说明用户名未定义。我将非常感谢我的代码的第二双眼睛。

这是功能文件:

@login

Feature: Valid Login
    As a employee,
    I want to login to my account
    So I can access the application

    Background: 
        Given the login page is displayed

    Scenario Outline: Manager enters correct login credentials and Ok button
        When the user enters their <username> and <password> correctly
        And the user clicks OK
        Then the page redirects to the manager home page

        Examples: Manager
            |   username            |   password                |
            | fake_name             | 1234                      |

这是 test_login_steps.py 代码:

from pytest_bdd import scenarios, scenario, given, when, then, parsers
from pages.signin import QaSigninPage
from pages.managerHomepage import QaManagerHomepage
import pytest


CONVERTERS = {
    'username': str,
    'password': str,
}

scenarios('../features/login.feature', example_converters=CONVERTERS)

# Create Page Objects
@pytest.fixture(scope='session')
def pages(test_manager):
    pages={"signin_PAGE": QaSigninPage(test_manager.browser),
            "manager_home_PAGE": QaManagerHomepage(test_manager.browser)}
    return pages


# Given Steps
@given('the login page is displayed')
def login_visit(pages):
    pages["signin_PAGE"].load()

@when('the user enters their <username> and <password> correctly')
def enter_credentials(pages):
    pages["signin_PAGE"].enter_username(username)
    pages["signin_PAGE"].enter_password(password)
4

2 回答 2

0

我忘了将变量传递给函数......我想通了。

于 2020-05-28T20:25:28.520 回答
0

当您使用 CONVERTERS 使用场景代替场景时,它允许您将示例作为参数传递

于 2020-06-19T06:32:04.167 回答