功能文件如下
功能:Nopcommerce 登录
场景:登录nopcommerce网站
Given nopcommerce page is displayed
When user enters username as admin@yourstore.com
When user enters password as admin
Then user is able to login to nocpmmerce website
步骤定义python文件如下
from pytest_bdd import scenarios, given, when, then
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pytest
scenarios('../features/NopcommerceLogin.feature')
@pytest.fixture()
def browser():
driver = webdriver.Safari()
yield driver
driver.quit()
@given("nopcommerce page is displayed")
def webpage(browser):
browser.get("http://admin-demo.nopcommerce.com")
@when("user enters username as admin@yourstore.com")
def enter_uname(browser):
browser.find_element_by_id("Email").send_keys("admin@yourstore.com")
@when("user enters password as admin")
def enter_pwd(browser):
browser.find_element_by_id("Password").send_keys("admin")
browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div/div[2]/div[1]/div/form/div[3]/input").click()
@then("user is able to login to nocpmmerce website")
def loginsuccess(browser):
assert browser.current_url == "https://admin-demo.nopcommerce.com/admin/"
运行 step_def 文件时,显示以下错误消息
回溯(最近一次通话最后):
文件“~/tests/step_defs/test_NopcommerceLogin.py”,第 6 行,在场景中('../features/NopcommerceLogin.feature')
文件“~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py”,第 343 行,场景 features_base_dir = get_features_base_dir(module)
文件“~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py”,第 295 行,在 get_features_base_dir return get_from_ini('bdd_features_base_dir', default_base_dir)
文件“~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py”,第 303 行,在 get_from_ini config = CONFIG_STACK[-1]
IndexError:列表索引超出范围