我无法使用行为和python进行前端浏览器堆栈测试。我设法编写了一个处理登录到Web应用程序的测试。我现在想做的是使用该逻辑作为我在用户面板中进行后续测试的背景规范。
我如何将我的第一个测试作为背景步骤实施,我到底要在steps.py中写些什么?
当我执行简单的步骤(如在第一次测试中不起作用)时,我得到的所有内容都未定义变量
我的登录测试如下:
.feature文件:
Feature: login functionality
Scenario: can login to panel
When visit url "https://"
When email field with name "mat-input-0" is given "florian@"
When password field with name "mat-input-1" is given "xxx"
When submit button with name "div.action-btns" is clicked
Then url becomes "https://xxx"
这是我的步骤文件:
import time
@when('visit url "{url}"')
def step(context, url):
context.browser.get(url)
@when('email field with name "{selector}" is given "{value}"')
def step(context, selector, value):
elem = context.browser.find_element_by_id(selector)
elem.send_keys(value)
@when('password field with name "{selector}" is given "{value}"')
def step(context, selector, value):
elem = context.browser.find_element_by_id(selector)
elem.send_keys(value)
@when('submit button with name "{selector}" is clicked')
def step(context, selector):
elem = context.browser.find_element_by_css_selector(selector).click()
time.sleep(5)
@then('url becomes "{url}"')
def step(context, url):
time.sleep(5)
assert context.browser.current_url == url
这有效,我想以此为基础进行进一步的测试。
我尝试过的是这样的:
.featurefile:
Feature: panel create server functionality
tests if it's possible to create a server
Background: Login to the panel with test account login data
Given the user is logged in the panel
When visit url "https://xxx"
When email field with name "mat-input-0" is given "xxx"
When password field with name "mat-input-1" is given "xxx"
When submit button with name "div.action-btns" is clicked
Then url becomes "https://xxx"
Scenario: user can create a server
When user clicks on new server tile with class "kachel kachel-add noDrag kachel-add-server"
When name field "server-name focus-first ng-valid-maxlength ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" is given "random name"
When connect to internet control "pubnet" is activated
Then ....