行为驱动测试(三) behave+webdriver

参数化
Feature:bss
  Scenario Outline: login bss success
    Given Access bss website
    When  Input  enter 
    And I click 登录 first
    Then I can see 组织架构 first
    When I click 组织架构 second
    Then I find 人员管理 second
    When I click 人员管理 third


    Examples: Amphibians
    |username        |passwords   |
    |13500000001  |123456         |
from selenium import webdriver
from behave import *
import time

@given('Access bss website')
def step_impl(self):
    self.driver = webdriver.Chrome()
    url = '--------------------------------'
    self.driver.get(url)

@when('Input {username} enter {passwords}')
def step_impl(self,username,passwords):
    self.driver.find_element_by_id('username').send_keys(username)
    self.driver.find_element_by_id('passwords').send_keys(passwords)
    time.sleep(2)
    print(username)
    print(passwords)

@when('I click {button} first')
def step_impl(self,button):
    self.driver.find_element_by_xpath('//button[contains(text(),button)]').click()
    time.sleep(16)

@then('I can see {org} first')
def step_impl(self, org):
    if org in self.driver.page_source:
        pass
    else:
        print('未找到org')

@when('I click {org} second')
def step_impl(self,org):
    self.driver.find_element_by_xpath('//*[@id="root"]/div/div[1]/div[2]/ul/li[1]/div/span/span[contains(text(),org)]').click()

@then('I find {person} second')
def step_impl(self,person):
    if person in self.driver.page_source:
        pass
    else:
        print('未找到person')
        print(person)

@when('I click {person} third')
def step_impl(self,person):
    self.driver.find_element_by_xpath('//a[contains(text(),person)]').click()
    time.sleep(10)

标签定位的处理方式:

'//button[contains(text(),button)]'

你可能感兴趣的:(行为驱动测试(三) behave+webdriver)