python+selenium测试用例参考
来源:互联网 发布:淘宝客新手怎么推广 编辑:程序博客网 时间:2024/04/28 18:21
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
import unittest,time,re
class Goodboy(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.base_url = "http://www.baidu.com"
self.verificationErrors = []
self.accept_next_alert = True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def login(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_xpath('//*[@id="accountInfo"]/li/a[1]').click()
driver.find_element_by_id('username').click()
driver.find_element_by_id('username').send_keys('p_goodbaby1@163.com')
time.sleep(2)
driver.find_element_by_id('password').click()
driver.find_element_by_id('password').send_keys('123456')
driver.find_element_by_xpath('//*[@id="loginBtn"]').click()
time.sleep(3)
self.username = driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dt/a[1]').text
if(self.username == u'百度用户名'):
print 'user matched!'
else:
raise NameError('user is not matched!')
def logout(self):
driver = self.driver
t = driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dt/a[1]')
ActionChains(driver).move_to_element(t).perform()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dd/div/p[6]/a[1]/b').click()
time.sleep(2)
def test_login_logout(self):
self.login()
self.logout()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
import unittest,time,re
class Goodboy(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.base_url = "http://www.baidu.com"
self.verificationErrors = []
self.accept_next_alert = True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def login(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_xpath('//*[@id="accountInfo"]/li/a[1]').click()
driver.find_element_by_id('username').click()
driver.find_element_by_id('username').send_keys('p_goodbaby1@163.com')
time.sleep(2)
driver.find_element_by_id('password').click()
driver.find_element_by_id('password').send_keys('123456')
driver.find_element_by_xpath('//*[@id="loginBtn"]').click()
time.sleep(3)
self.username = driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dt/a[1]').text
if(self.username == u'百度用户名'):
print 'user matched!'
else:
raise NameError('user is not matched!')
def logout(self):
driver = self.driver
t = driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dt/a[1]')
ActionChains(driver).move_to_element(t).perform()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="accountInfo"]/li[1]/dl/dd/div/p[6]/a[1]/b').click()
time.sleep(2)
def test_login_logout(self):
self.login()
self.logout()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
0 0
- python+selenium测试用例参考
- selenium+python测试全部用例
- python selenium执行所有测试用例并生成报告
- python + selenium 自动化测试
- selenium + python 自动化测试
- Python自动化测试-Selenium
- selenium + python 自动化测试
- selenium python 测试google脚本
- python selenium 完整测试脚本
- Python + Selenium网页自动化测试
- python编程之Selenium测试
- Selenium+Python 自动化测试模型
- python+selenium 自动化测试webui
- python+selenium自动化测试封装
- Python Selenium 自动测试网页
- Selenium+Python:Web自动化测试
- selenium+python自动化测试笔记
- python+selenium自动化软件测试
- Unity Shader 学习笔记 (一) 创建Shader自带代码解读
- 在SAP中进行黏贴时必须要把之前的数据删掉后才能黏贴,不能直接使用黏贴来覆盖之前的数据,这个怎麼解?
- Note_20150814_C++_Function
- 让Excel飞!职场Office效率提升秘籍(第2版)——互动出版网
- NSString & Unicode
- python+selenium测试用例参考
- 虚函数——C++PrimeCr第五版读书笔记
- hdu5386 棋盘涂色模拟
- c#获取程序版本号
- Android 之 Binder与进程间通信
- OwnCloud搭建
- HTML 编辑器
- Microsoft ACE OLEDB 12.0 数据库连接字符串
- node.js 小爬虫