码迷,mamicode.com
首页 > 其他好文 > 详细

Selenium3.0 自动化测试

时间:2016-10-05 15:18:09      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

  早在2013年的时候,Selenium官方宣布,Selenium新的版本会在圣诞节的时候发布。但是,他们并没有说哪一个圣诞节发布。

  转眼的三年过去了,目前已经发布到Selenium3.0 beta4版本,这将会是Selenium3.0正式版本前的最后一个测试版本。

  尽管我对Selenium3.0比较失望(本以为它会集成移动端的自动化测试)。但是,它还是做了一些变动。

 

Selenium3.0的变化                 

  最大的变化应该是去掉了Selenium RC 了,这是必然的结果。Selenium RC Selenium1.0的产物,Selenium2.0WebDriver为主,经过这么多年有发展,Selenium RC已经很少有人在用了。Selenium3.0版本去掉是个必然的结果。

  • You’ll need to be running Java 8 to use the Java pieces of Selenium. This is the oldest version of Java officially supported by Oracle, so hopefully you’re using it already!

  Selenium3.0只支持Java8版本以上,所以,如果你是用Java+Selenium开发自动化测试,那么Java JDK需要升级到Java8了,对于其它编程来说可以忽略这点,除非你要使用Selenium Grid

  Selenium3.0中的Firefox驱动独立了,在Selenium3.0之前,只要在不同编程语言下安装好Selenium就可以驱动Firefox浏览器运行自动化测试脚本。这是因为不同语言下的Selenium库中移动包含了Firefox浏览驱动。

  然而,现在Firefox浏览器驱动与Selenium库分离,单独提供下载。

  下载地址:https://github.com/mozilla/geckodriver/releases

  不过,geckodriver驱动要求Friefox浏览器必须48版本以上。

  • Support for Safari is provided on macOS (Sierra or later) via Apple’s own safaridriver.

  Safari是苹果公司的浏览器,然后,它也早就实现了多平台的支持,同样可以在Windows下运行,然而,它的驱动比较有意思,是集成到Selenium Server中的。也就是说你想让自动化测试脚本在Safari浏览器上运行,必须使用Selenium Server

  • Support for Edge is provided by MS through their webdriver server.
  • Only versions 9 or above of IE are supported. Earlier versions may work, but are no longer supported as MS no longer supports them.

 

如何使用浏览器驱动                                       

   读者可以单独创建一个目录,如:D:/drivers/ ,把不同浏览器的驱动都放到该目录。geckodriver.exeFirefox)、chromedriver.exeChrome)、MicrosoftWebDriver.exeEdge)、IEDriverServer.exeIE)、operadriver.exeOpera)等。

  然后,将D:/drivers/添加到系统环境变最path下面即可。

 

Python安装Selenium3.0                                                   

 通过pip安装,3.0.0b3为当前最新版本。

>pip install selenium==3.0.0b3

Selenium3.0API没有任何改变,跑个简单的例子验证一下。 

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.baidu.com")

driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click()

driver.quit()

 

 

Java安装Selenium3.0                                                        

  下载Selenium Server 3.0.0-beta4为当前最新版本:http://www.seleniumhq.org/download/

 技术分享

   打开Eclipse,导入:如下图:

 技术分享

  同样通过一个简单的例子来验证Selenium3.0工作正常。 

package base.test.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.*;

public class BaiduTest {
    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.baidu.com/");
        driver.findElement(By.id("kw")).sendKeys("selenium java");
        driver.findElement(By.id("su")).click();
        driver.quit();
    }

}

 

Selenium3.0 自动化测试

标签:

原文地址:http://www.cnblogs.com/fnng/p/5932224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!