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

feature 文件

# Created by doudou at 2018/5/6

Feature:bss

 # 登录成功
  Scenario Outline: login bss success
    # 打开站点地址
    Given Access bss website
    # 输入正确账号和正确密码
    When  Input right  Input right 
    # 点击登录
    And click login
    # 判断可以看见组织架构
    Then  There are 组织架构 displaying

  Examples:Amphibians
  |   username   |   passwords   |
  | 13500000001  |   123456qwe   |
  | 13500000002  |  111111111111  |

py文件

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} Input right {passwords}')
def step_impl(self,username,passwords):
    # 定位账号输入框 并输入
    self.driver.find_element_by_id('username').send_keys(username)
    time.sleep(2)
    # 定位密码输入框 并输入
    self.driver.find_element_by_id('passwords').send_keys(passwords)

@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,未能成功找到预期结果')

终端运行:behave feature文件的所在地址

终端运行截图:
行为驱动测试_behave+python(二)_第1张图片
image

批量执行feature 文件

终端 behave feature 文件所在父文件的路径

你可能感兴趣的:(行为驱动测试_behave+python(二))