Permalink
Browse files

changed readme.md and comments to cover both 2.53.1 and 3.0.1 of WebD…

…river
  • Loading branch information...
1 parent ac900eb commit dd6c061aa2e6a2b004826a284c2bcc2506dd5b88 eviltester committed Oct 19, 2016
View
@@ -5,8 +5,7 @@ Source code to support getting started using Selenium WebDriver with Java
The source code has only really been uploaded in case people encounter problems following the instructions or make a very simple mistake that they cannot figure out.
-Please read the comments below, and the source code comments if you are having trouble starting work with Firefox. Especially if you are using Firefox v 47.
-
+Please read the comments below, and the source code comments if you are having trouble starting work with Firefox.
## Steps
@@ -17,27 +16,70 @@ Please read the comments below, and the source code comments if you are having t
* [WebDriver Install Checklist](https://github.com/eviltester/startUsingSeleniumWebDriver/blob/master/speedrun_install_checklist.md)
+If you are using Chrome and have added ChromeDriver to the path then use the command line:
+
+`mvn test -Dtest=MyFirstChromeTest`
+
+**For Firefox see the notes below for the version of Selenium WebDriver you are using.**
+
+Do not run `mvn test` because some of the tests are WebDriver version dependant and at least one will fail.
*Author: Alan Richardson*
* [SeleniumSimplified.com](http://seleniumsimplified.com)
* [Compendium Developments](http://compendiumdev.co.uk)
-## Notes
+See related blog posts:
+
+* http://seleniumsimplified.com/2016/10/update-on-marionette-geckodriver-v0-11-1-q-should-you-try-it-a-yes-you-should/
+* http://seleniumsimplified.com/2016/10/upgrading-to-selenium-3-with-my-first-selenium-project/
+
+
+## Notes for Selenium WebDriver 3.0.1
+
+### Running with Firefox
+
+If you are using Firefox 45 Extended Release version (or Firefox < v48) then to run the test from the command line use:
+
+`mvn test -Dtest=MyFirstLegacyFFTest`
+
+If you are using Firefox 48+ and have added Marionette `geckodriver.exe` to the path then use the command line:
+
+`mvn test -Dtest=MyFirstTest`
+
+The following will also work with Firefox 48+, but will fail in a future version of WebDriver because the `MarionetteDriver` is deprecated.
+
+`mvn test -Dtest=MyFirstTestFF48`
+
+### Running with Chrome
+
+If you are using Chrome and have added ChromeDriver to the path then use the command line:
-If you are using Firefox 45 Extended Release version then to run the test from the command line use:
+`mvn test -Dtest=MyFirstChromeTest`
+
+## Notes for Selenium WebDriver 2.53.1
+
+### Running with Firefox
+
+If you are using Firefox 45 Extended Release version (or Firefox < v48) then to run the test from the command line use:
`mvn test -Dtest=MyFirstTest`
-If you are using Firefox 48+ and have added Marionette to the path then use the command line:
+If you are using Firefox 48+ and have added Marionette `geckodriver.exe` to the path (renamed to `wires.exe`) then use the command line:
`mvn test -Dtest=MyFirstTestFF48`
+### Running with Chrome
+
If you are using Chrome and have added ChromeDriver to the path then use the command line:
`mvn test -Dtest=MyFirstChromeTest`
+## Update 19th October 2016
+
+Updated the Notes to cover Firefox on WebDriver 2.53.1 and 3.0.1.
+
## Update 4th October 2016
* Added the Mac Instructions, and moved Java install to the [Java checklist and project](https://github.com/eviltester/startUsingJavaJUnit/blob/master/speedrun_install_java_checklist.md)
View
@@ -25,28 +25,30 @@
- http://seleniumsimplified.com/2016/06/using-portable-firefox-46-with-webdriver/
-->
+ <!-- Explanation of versions
+ 3.0.1
+ Firefox 48+ - geckodriver.exe on path and use MyFirstTest to run in Firefox
+ Firefox < 48 - use MyFirstLegacyFFTest
+ 2.53.1
+ Firefox < 48 - use MyFirstTest to run in Firefox
+ Firefox 48+ - geckodriver.exe renamed to wires.exe and on path and use MyFirstTestFF48
+
+ Version Independent
+ MyFirstChromeTest will work if ChromeDriver is on the path for either version
+ -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
+ <!-- 19/October.2016
+ version 3.0.1 will work,
+ have just left as v 2.53.1 for the moment,
+ you can upgrade by deleting the above line and
+ removing the html comment tags from the line below -->
+ <!-- <version>3.0.1</version> -->
</dependency>
- <!--
- When Selenium 2.53.1 was available but not released to maven central I used the following
- code to use the new version. As written up in this blog post
- http://seleniumsimplified.com/2016/06/use_selenium_webdriver_jar_locally/
- -->
- <!--
- <dependency>
- <groupId>selenium_2_53_1</groupId>
- <artifactId>com.seleniumhq.selenium_2_53_1 </artifactId>
- <version>2.53.1</version>
- <scope>system</scope>
- <systemPath>C:/Users/Alan/Downloads/selenium-2.53.1/selenium-server-standalone-2.53.1.jar</systemPath>
- </dependency>
- -->
-
<dependency>
<groupId>junit</groupId>
@@ -0,0 +1,56 @@
+package com.eviltester.webdriver;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+/* run the test code against Firefox v < 48 with the inbuilt Firefox Driver in WebDriver 3 */
+public class MyFirstLegacyFFTest {
+
+ @Test
+ public void startWebDriver(){
+
+
+ /* Use the built in FirefoxDriver to run a version of Firefox < 48
+ You do not neet to have Marionette geckodriver.exe or wires.exe on the path.
+ You do need to be using v 3 of WebDriver */
+ DesiredCapabilities capabilities = DesiredCapabilities.firefox();
+ capabilities.setCapability("marionette", false);
+
+ /* If Firefox < v48 is not your default browser then you need to tell WebDriver where it is,
+ so uncomment the line below and amend the path to the location of your firefox.exe
+ the example code uses FirefoxPortable from
+ https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./
+ */
+ //capabilities.setCapability("firefox_binary", new File(System.getProperty("user.dir"),"/tools/FirefoxPortable/FirefoxPortable.exe").getAbsolutePath());
+ WebDriver driver = new FirefoxDriver(capabilities);
+
+
+ // The actual test code follows assumes that you have either
+ // - been able to instantiate FirefoxDriver or
+ // - downloaded firefox portable and instantiated a driver with FirefoxBinary
+ driver.navigate().to("http://seleniumsimplified.com");
+
+ Assert.assertTrue("title should start differently",
+ driver.getTitle().startsWith("Selenium Simplified"));
+
+ driver.close();
+ driver.quit();
+ }
+
+ /**
+ * Notes on Firefox Portable
+ * You could also use portable Firefox WebDriver on Windows
+ * Which you could download from sourceforge
+ * https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./
+ *
+ * I downloaded this version from sourceforge
+ * https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./Mozilla%20Firefox%2C%20Portable%20Edition%2046.0.1/
+ *
+ * I extracted it to a tools directory at the same level of the source folder
+ * And then use the following code to start the firefox
+ */
+
+}
@@ -5,94 +5,24 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
-// import the driver class to allow us to use Firefox Driver
-// uncomment the next line to use the MarionetteDriver
-//import org.openqa.selenium.firefox.MarionetteDriver;
-
public class MyFirstTest {
@Test
public void startWebDriver(){
- /**
- * If you are using Firefox 47 or a version of firefox that does not support the inbuilt
- * WebDriver Firefox driver then you will see firefox crash and an error like
- * "org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
- *
- * You will need to use one of the other methods listed:
- * e.g.
- * - portable firefox
- * or download firefox 45 ESR https://www.mozilla.org/en-US/firefox/organizations/all/
- * - marionette/GeckoDriver
- *
- * see the following blogs for details
- * - http://www.theautomatedtester.co.uk/blog/2016/selenium-webdriver-and-firefox-47.html
- * - http://seleniumsimplified.com/2016/04/how-to-use-the-firefox-marionette-driver/
- * - http://seleniumsimplified.com/2016/06/using-portable-firefox-46-with-webdriver/
- */
-
/** NOTE:
- * The following code will work on Firefox versions which support in built FirefoxDriver
- * e.g. 46 and below and 47.1
- * It will not work on Firefox versions which require Marionette (48)
- * If you want to keep using FirefoxDriver then use Firefox version 45 then you can download it from here:
- * https://www.mozilla.org/en-US/firefox/organizations/all/
+ * This test will work on
+ * - WebDriver 2.53.1
+ * - Firefox v < 48
+ * And on
+ * - WebDriver 3
+ * - Firefox 48+
+ * - geckodriver.exe on the path
*/
WebDriver driver = new FirefoxDriver();
-
-
- /**
- * Another option -
- * You could also use portable Firefox WebDriver on Windows
- * Which you could download from sourceforge
- * https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./
- *
- * I downloaded this version from sourceforge
- * https://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./Mozilla%20Firefox%2C%20Portable%20Edition%2046.0.1/
- *
- * I extracted it to a tools directory at the same level of the source folder
- * And then use the following code to start the firefox
- */
- //FirefoxProfile profile = new FirefoxProfile();
- //WebDriver driver = new FirefoxDriver(
- // new FirefoxBinary(
- // new File(System.getProperty("user.dir"),
- // "/tools/FirefoxPortable/FirefoxPortable.exe")
- // ),profile);
-
- /**
- * Another option is to use the Marionette/GeckoDriver
- * This is the official FirefoxDriver that is under development
- * https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
- *
- * You can either:
- * - define the location as a property
- * - or add the folder where you donwnloaded it to the path
- *
- */
- /* The following code is for the Marionette Driver
- You need to uncomment out the next 4 lines to use the marionette driver
- You also need to download the Marionette executable
- https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
- */
- // String currentDir = System.getProperty("user.dir");
- // String marionetteDriverLocation = currentDir + "/tools/marionette/wires.exe";
- // System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
-
- //If you add the folder with wires.exe to the path then you only need the following line
- // and you don't need to set the property as listed in the 3 lines above
- // e.g. D:\Users\Alan\Documents\github\startUsingSeleniumWebDriver\tools\marionette
- //WebDriver driver = new MarionetteDriver();
-
-
- // The actual test code follows assumes that you have either
- // - been able to instantiate FirefoxDriver or
- // - downloaded firefox portable and instantiated a driver with FirefoxBinary
- // - or using Marionette/GeckoDriver and set the webdriver.gecko.driver and instantiated MarionetteDriver
- // - or added the path of wires.exe to the system path and instantiated MarionetteDriver
driver.navigate().to("http://seleniumsimplified.com");
Assert.assertTrue("title should start differently",
@@ -5,9 +5,6 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
-// import the driver class to allow us to use Firefox Driver
-// uncomment the next line to use the MarionetteDriver
-//import org.openqa.selenium.firefox.MarionetteDriver;
public class MyFirstTestFF48 {
@@ -16,14 +13,20 @@ public void startWebDriver(){
/* The following code is for the Marionette Driver
+ this will work in v 2.53.1 and v 3.0.0 and 3.0.1 of WebDriver
+ but is deprecated in v 3.0.1 of WebDriver so may not work in future versions
You also need to download the Marionette executable
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
+
+ for version 2.53.1 of webdriver, rename geckodriver.exe to wires.exe
*/
+
+ /* You can set the path to the actual file location of the driver */
// String currentDir = System.getProperty("user.dir");
// String marionetteDriverLocation = currentDir + "/tools/marionette/wires.exe";
// System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
- //If you add the folder with wires.exe to the path then you only need the following line
+ //If you add the folder with geckodriver.exe (wires.exe) to the path then you only need the following line
// and you don't need to set the property as listed in the 3 lines above
// e.g. D:\Users\Alan\Documents\github\startUsingSeleniumWebDriver\tools\marionette
WebDriver driver = new MarionetteDriver();
@@ -33,7 +36,8 @@ public void startWebDriver(){
// - been able to instantiate FirefoxDriver or
// - downloaded firefox portable and instantiated a driver with FirefoxBinary
// - or using Marionette/GeckoDriver and set the webdriver.gecko.driver and instantiated MarionetteDriver
- // - or added the path of wires.exe to the system path and instantiated MarionetteDriver
+ // - or added the path of geckodriver.exer (wires.exe) to the system path and instantiated MarionetteDriver
+
driver.navigate().to("http://seleniumsimplified.com");
Assert.assertTrue("title should start differently",

0 comments on commit dd6c061

Please sign in to comment.