Selenium3.5起步配置

Selenium 3.5 – Complete Guide to the latest Selenium WebDriver

环境信息:

JDK 1.8

Selenium 3.5.3

GeckoDriver V0.18.0-win64

Moz FF V55.0.3

OS:Win7, Win10, Win Server 2012 (passed)


Part One: General Info

Selenium Latest Version

As on 06 September 2017, the latest version of Selenium WebDriver for Java is Selenium 3.5.3

Selenium 3 Important Features

1.      Minimum version of Java required to run Selenium 3 is Java 8+;

2.     You wouldneed to use GeckoDriver if you want to run your scripts in Firefox versions greater than 47.0.1. Firefox 47.0.1 and before would not need GeckoDriver;

3.      Apple has come up with its own SafariDriver to let you run your tests in Safari on Mac;

4.      Guava has been updated to version 21;

 

There are a lot more minor features and updates with different versions of Selenium WebDriver.This list of new features and change log is available here.

https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG

 

Download and Install Selenium

Check if you have Java8+ on your machine

Command: Java-version

Doc: http://www.automationtestinghub.com/download-and-install-java/

 

Download and Install Eclipse IDE for Java (Optional)

Current Eclipse could support Selenium3.5.

Doc: http://www.automationtestinghub.com/eclipse-ide-download-and-install/

 

Download and Install the latest version of Selenium WebDriver (Version3.5.3)

Doc: http://www.automationtestinghub.com/download-and-install-selenium/

Selenium WebSite: http://www.seleniumhq.org/download/

 

Based on what browser you want to use to write your test scripts, setup corresponding webdriver:

Use GeckoDriver to Launch Firefox

Doc:

http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/

 

Launch Chrome browser with Selenium

Doc: http://www.automationtestinghub.com/selenium-chromedriver/

 

Lanuch Microsoft Edge Browser with Selenium

Doc: http://www.automationtestinghub.com/selenium-3-launch-microsoft-edge-with-microsoftwebdriver/


 

Part Two: Setup Steps

1.       Check Java version and make sure is 8+

2.       Selenium jar download: http://www.seleniumhq.org/download/


UnZip the download jar.



Will uses client-combined-3.5.3-nodeps.jar and jars in libs folder.

3.     Download and set GeckoDriver

Download link: https://github.com/mozilla/geckodriver/releases

There are two versions of GeckoDriver for Windows: 32-bit and 64-bit. Based on whether your Firefox is 32-bit or 64-bit, you need to download the corresponding GeckoDriver exe.

 



LaunchFirefox Method 2 : Set property in Environment Variables



 

4.       Update your Firefox to the latest version.

 


5.     Code your first “Hello World”

Create a java project and import the selenium jars. (Abovestep2)



Run it.



Firefox browser starts up. Great!

 


 

Part XX: Other Info

Important reference doc:

http://www.automationtestinghub.com/selenium-3/

 What is Selenium GeckoDriver?

Let us first start with the very basics – What isGecko and GeckoDriver? Gecko is a web browser engine used in many applicationsdeveloped by Mozilla Foundation and the Mozilla Corporation, most noticeablythe Firefox web browser, its mobile version other than iOS devices, their emailclient Thunderbird and many other open source software projects. You can getmore information about Gecko here – https://en.wikipedia.org/wiki/Gecko_(software)

GeckoDriver is a proxy for using W3CWebDriver-compatible clients to interact with Gecko-based browsers i.e. MozillaFirefox in this case. This program provides the HTTP API described by theWebDriver protocol to communicate with Gecko browsers. It translates calls intothe Marionette automation protocol by acting as a proxy between the local andremote ends.

Two Launch Firefox Methods

Launch Firefox Method 1 : webdriver.gecko.driver system property

With this method, you will have to add an additional line of code in your test case.

 

Follow the steps given below to use this method –

1. Copy the entire path where you unzipped geckodriver.exe. Let us assume that the location is – D:\Firefox\geckodriver.exe.You will need to add System.setProperty with the driver location to your code.

The code to launch Firefox browser would look like this :


Important Note 1: In the folder paths in the below code, we have used double backslash (\\). This is because Java treats single back slash (\) as an escape character. So you would need to use double back slash, everywhere you add some folder path.

 

Important Note 2: If you are using older versions of GeckoDriver (v0.16.1 or before), then you will also need to provide the Firefox Binary, otherwise you might get the below error –

org.openqa.selenium.SessionNotCreatedException:Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided, and no binary lag set on the command line

But please note that this is neededonly for GeckoDriver v0.16.1 or before. So for older Gecko versions,please use the below code where Firefox binary location has been provided using FirefoxOptions class.

 

2. Run this code to verify that everything is working fine. You will notice that google.com gets opened in new Firefox window

 

Launch Firefox Method 2 : Set property in Environment Variables

1. Copy the entire folder location where geckodriver.exe is saved. If the entire path is D:\Firefox\geckodriver.exe,then the folder location would be D:\Firefox\

2. Open Advanced tab in System Properties window and set to Path property.

 

For GeckoDriver v0.17.0 and v0.18.0 –


For GeckoDriver v0.16.1 or before –

 


Use DesiredCapabilities and Firefox Options to launch Firefox with Selenium GeckoDriver


3. Run this code to verify that everything is working fine. You will notice that google.com gets opened in new Firefox window

 

GeckoDriver ReadMe file:

https://github.com/mozilla/geckodriver/blob/master/README.md

Guava ReadMe file:

https://github.com/google/guava/wiki

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值