python+selenium实现跨浏览器兼容性测试
python
https://www.python.org/
python是一种脚本语言, 易学易用,可以助你快速实现业务逻辑,高效集成系统。
----- http://zh.wikipedia.org/zh-cn/Python:
它的语法简单,与其它大多数程序设计语言使用大括号不一样,它使用缩进来定义语句块。
Python经常被用于Web开发。比如,通过mod_wsgi模块,Apache可以运行用Python编写的Web程序。使用Python语言编写的Gunicor
n作为Web服务器,也能够运行Python语言编写的Web程序。Python定义了WSGI标准应用接口来协调Http服务器与基于Python的Web程序之间的沟通。一些Web框架,如Django、Pyramid、TurboGears、Tornado、web2py、Zope、Flask等,可以让程序员轻松地开发和管理复杂的Web程序。
download: https://www.python.org/downloads/release/python-279/
selenium python bindings
selenium python bindings 提供一套简单的API,通过这些API调用了Selenium WebDriver,可以实现功能测试和验收性测试用例。
可以支持对 Firefox 和 IE 和 chrome的调用。
官网介绍:
http://selenium-python.readthedocs.org/installation.html#introduction
windows安装
1、 下载安装python3.4 https://www.python.org/ftp/python/3.4.2/python-3.4.2.msi
2、使用cmd.exe执行如下命令,安装selenium python bindings
C:\Python34\Scripts\pip.exe install selenium
3、下载IEdriver 和 chromedriver,并放到python安装目录下 (C:\Python34)
https://github.com/fanqingsong/daydayup/blob/master/CSoftware/webdriver/IEDriverServer.exe
https://github.com/fanqingsong/daydayup/blob/master/CSoftware/webdriver/chromedriver.exe
firefox不需要驱动
使用方法待研究驱动:
https://github.com/dineshkummarc/operadriver
https://github.com/mfazekas/safaridriver
4、可以运行python的测试脚本了,例如:
C:\Python34\python.exe C:\my_selenium_script.py
官网安装介绍:
http://selenium-python.readthedocs.org/installation.html#downloading-python-bindings-for-selenium
测试脚本
下面脚本实现, 打开baidu网页,搜索一个关键字, 依次执行三个浏览器(firefox ie chrome)。
#import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys # test case
def testbrowser(driver):
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").click()
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("vx")
driver.find_element_by_id("su").click()
driver.implicitly_wait(30)
time.sleep(3)
driver.close()
driver.quit()
return None driverfirefox = webdriver.Firefox()
testbrowser(driverfirefox) driverie = webdriver.Ie()
testbrowser(driverie) driverchrome = webdriver.Chrome()
testbrowser(driverchrome)
测试用例testbrowser代码可以使用 selenium IDE导出的脚本中截取主体部分:
# -*- 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.common.exceptions import NoAlertPresentException
import unittest, time, re class Baidupython(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True def test_baidupython(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").click()
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("vx")
driver.find_element_by_id("su").click() def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return 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 tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
unittest.main()
也可以自己写脚本,使用selenium driver的提供的api:
http://selenium-python.readthedocs.org/locating-elements.html
python教程:
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0013747381369301852037f35874be2b85aa318aad57bda000
python+selenium实现跨浏览器兼容性测试的更多相关文章
- Selenium Grid跨浏览器-兼容性测试
		
Selenium Grid跨浏览器-兼容性测试 这里有两台机子,打算这样演示: 一台机子启动一个作为主点节的hub 和 一个作为次节点的hub(系统windows 浏览器为ie) ip为:192.16 ...
 - Selenium_python自动化跨浏览器执行测试
		
Selenium_python自动化跨浏览器执行测试(简单多线程案例) 转:https://www.cnblogs.com/dong-c/p/8976746.html 跨浏览器测试是功能测试的一个分 ...
 - Web浏览器兼容性测试工具如何选择
		
对于前端开发工程师来说,网页兼容性测试工程师而言,确保代码在各种主流浏览器的各个版本中都能正常工作是件很费时的事情,幸运的是,有很多优秀的工具可以帮助测试浏览器的兼容性,领测软件测试网向您推荐12款很 ...
 - Web前端页面的浏览器兼容性测试心得(二)搭建原汁原味的IE8测试环境
		
如果你做的页面被老板或PM要求兼容IE8,你就值得同情了.IE8不支持HTML5,在2017年的前端界,开发者不涉及HTML5标准简直寸步难行.然而,有一个可怕的事实客观存在,那就是IE8是Win7系 ...
 - Python+Selenium自动化-设置浏览器大小、刷新页面、前进和后退
		
Python+Selenium自动化-设置浏览器大小.刷新页面.前进和后退 1.设置浏览器大小 maximize_window():设置浏览器大小为全屏 set_window_size(500,5 ...
 - Selenium_python自动化跨浏览器执行测试(简单多线程案例)
		
发生背景: 跨浏览器测试是功能测试的一个分支,用以验证web应用在不同浏览器上的正常工作,通常情况下,我们都期望web类应用能够被我们的用户在任何浏览器上使用,例如有的人喜欢IE浏览器上使用,有的人喜 ...
 - [技术博客]基于动态继承类、WebDriver的浏览器兼容性测试框架搭建
		
问题背景 观察使用selenium进行自动化测试的过程,我们可以将它概述为: 启动测试进程,在该进程中构建WebDriver 启动浏览器进程,将它与WebDriver建立连接 使用WebDriver向 ...
 - 试用saucelabs进行浏览器兼容性测试
		
Hi,all 跟大家分享下saucelabs,一个云测试平台,支持PC和手机(自带的)浏览器的兼容性测试,并且支持selenium/appium的自动化测试,不过是收费的,价格还挺贵,但是人工的测试是 ...
 - python selenium模块调用浏览器的时候出错
		
python selenium模块使用出错,这个怎么改 因为不同版本更新不同步问题,浏览器都要另外下一个驱动.
 
随机推荐
- django通过middleware计算每个页面的详细执行时间
			
你可以自定义一个MiddleWare类,然后在settings.py引用这个中间件,添加到MIDDLEWARE_CLASSES里,然后在公共模板里添显示代码即可. 添加到公共模板里的代码: <d ...
 - [转]PHP高效率写法(详解原因)
			
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非静 ...
 - Tiffany
			
--名称:Tiffany&Co(蒂芙尼) --总部:美国,纽约 --历史:1837年创立 --产品:珠宝.手表. 配饰.礼品 --特点:品牌,质量,奢饰品
 - simplify the design of the hardware forming the interface between the processor and thememory system
			
Computer Systems A Programmer's Perspective Second Edition Many computer systems place restrictions ...
 - document.execCommand(”BackgroundImageCache”, false, true)
			
很多时候我们要给一些按钮或是img设置背景,而为了达到数据与表现样式分离的效果,通常背景样式都是在CSS里设定的,但是这个行为在IE会有一 个Bug,那就是因为 IE默认情况下不缓存背景图片,所以当鼠 ...
 - su terminal get around---docker root
			
su : must be run from a terminal After some googling, I found the solution from Tero's glob. If you ...
 - Cloudera Hadoop什么是CDH及CDH版本介绍
			
本文引用自:Cloudera Hadoop什么是CDH及CDH版本介绍http://www.aboutyun.com/thread-6788-1-1.html(出处: about云开发) 云技术新兴的 ...
 - 防止sql注入,过滤敏感关键字
			
//sql过滤关键字 public static bool CheckKeyWord(string sWord) { //过滤关键字 string StrKeyWord = @"select ...
 - Cocos2d-JS切换场景与切换特效
			
var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function () { //////////////////////////// ...
 - zendstudio
			
如何查看大纲类 1.浏览 ->大纲 2.窗口->显示视图->大纲 在php中 右键 ->源代码->格式,方便我们整理代码