最近公司让使用robortframework-进行ui测试-入门一下
【目前多数的ui是这么写的,结合unittest /pytest来运行】
方式1(关键字驱动):
#coding=utf-8
#python3
import time
from selenium import webdriver
# 屏蔽chrome 消息通知
options = webdriver.ChromeOptions()
prefs = {
'profile.default_content_setting_values' :
{
'notifications' : 2
}
}
options.add_experimental_option('prefs',prefs)
driver = webdriver.Chrome(chrome_options = options)
driver.get("https://xxx.com.login")
driver.implicitly_wait(10)
driver.find_element_by_id("userEmail").send_keys("xxx@soso.com")
time.sleep(2)
driver.find_element_by_id("userPassword").send_keys("123456")
time.sleep(2)
driver.find_element_by_class_name("reg_submit").click()
方式2(数据驱动):
#coding=utf-8
from selenium import webdriver
file_info = open('info.txt','r')
values = file_info.readlines()
file_info.close()
for serch in values:
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
driver.find_element_by_id('kw').send_keys(serch)
driver.find_element_by_id('su').click()
driver.quit()
——————————————————————————————————
【robofframework结合pabot来运行】
方式1(关键字驱动):
*** Settings *** Library SeleniumLibrary *** Test Cases *** 使用百度搜索京东 Open Browser http://www.baidu.com chrome Input Text id=kw 京东 Click Button id=su Sleep 3 Click Element partial link=京东 Sleep 3 Close Browser
方式2(数据驱动):
*** Settings ***
Library SeleniumLibrary
Test Setup Open Browser https://github.com/login chrome
Test Teardown Close Browser
Test Template 登录Github
*** Test Cases ***
测试登录Github
tom 123
kite 456
rose 789
*** Keywords ***
登录Github
[Arguments] ${username} ${pwd}
Input Text id=login_field ${username}
Input Password id=password ${pwd}
Click Button name=commit
Sleep 3
————————————————————————————————————————————————————————————————
说明:
1.robotframework主要以keywords进行,ta就是封装的方法直接拿来使用即可
2.查找路径:pip list-->pip show package -->SeleniumLibrary 目录下-->keywords
3.参考:https://codingdict.com/article/28515