行为驱动测试_behave+python(一)

feature文件

Feature:bss # 登录成功 Scenario: login bss success # 打开站点地址 Given Access bss website # 输入正确账号和正确密码 WhenInput right username right Input passwords # 点击登录 And click login # 判断可以看见组织 ThenThere are 组织 displaying

测试文件
from selenium import webdriver from behave import * import time@given('Access bss website') def step_impl(self): # 初始化浏览器获取浏览器类型 self.driver = webdriver.Firefox() url = '------------------------------' # 获取url地址 self.driver.get(url) time.sleep(3)@when('Input right username right Input passwords') def step_impl(self): # 定位账号输入框 并输入 self.driver.find_element_by_id('username').send_keys('13500000001') time.sleep(2) # 定位密码输入框 并输入 self.driver.find_element_by_id('passwords').send_keys('123456qwe')@when('click login') def step_impl(self): # 登录 self.driver.find_element_by_css_selector('.ant-btn').click() time.sleep(10)@Then('There are 组织 displaying') def step_impl(self): # 根据类名获取div self.ele_results = self.driver.find_element_by_css_selector("div.ant-menu-submenu-title") self.expected_results = '组织' if self.expected_results in self.ele_results.text: print('ture,可以找到组织两个字') else: print('false,未能成功找到预期结果')

    推荐阅读