rselenium download driver rsDriver : Start a server and browser. what version of Chrome driver to run. Default = "latest" which runs the most recent version. To see other version currently sourced run binman::list_versions("chromedriver"), A value of NULL excludes adding the chrome browser to Selenium Server. what version of driver to run. Default = "latest" which runs the most recent version. To see other version currently sourced run binman::list_versions("geckodriver"), A value of NULL excludes adding the browser to Selenium Server. what version of IEDriverServer to run. Default = "latest" which runs the most recent version. To see other version currently sourced run binman::list_versions("iedriverserver"), A value of NULL excludes adding the browser to Selenium Server. NOTE this functionality is Windows OS only. what version of PhantomJS to run. Default = "2.1.1" which runs the most recent stable version. To see other version currently sourced run binman::list_versions("phantomjs"), A value of NULL excludes adding the PhantomJS to Selenium Server. If TRUE, include status messages (if any) If TRUE check the versions of selenium available and the versions of associated drivers (chromever, geckover, phantomver, iedrver). If new versions are available they will be downloaded. Additional arguments to pass to remoteDriver. Details. This function is a wrapper around selenium . It provides a "shim" for the current issue running firefox on Windows. For a more detailed set of functions for running binaries relating to the Selenium/webdriver project see the wdman package. Both the client and server are closed using a registered finalizer. Value. A list containing a server and a client. The server is the object returned by selenium and the client is an object of class remoteDriver. Driving OS/Browsers Local and Remote. The goal of this vignette is to give a basic overview of how one might approach using RSelenium with combinations of operating systems (OS) and browsers both locally and remotely. RSelenium with Local Fully-fledged Browsers. Firefox. The default browser for RSelenium is firefox. When a remoteDriver class is instantiated using default options for example remdr <- remoteDriver() then the browser listed is firefox. Other browsers can be driven using RSelenium . We shall split these browsers into three groups. Full-fledged browsers, headless browsers and mobile browsers. The standalone selenium jar has the ability to drive other full-fledged browsers such as chrome, internet explorer, and . First we shall look at how to drive chrome using RSelenium. Chrome. Firstly we note that chrome in this instance can be considered as having three parts. There is the browser itself (“chrome”), the language bindings provided by the Selenium project (“the driver”) and an executable downloaded from the project which acts as a bridge between “chrome” and the “driver”. This executable is called “chromedriver”. We need to have a “chromedriver” running. First we need to locate one. The download directory for chromedriver is currently located at http://chromedriver.storage.googleapis.com/index.html. In this example we shall look at running chrome on a windows platform so we will download the windows chromedriver. The most uptodate version of chromedriver at the time of writing was 2.9. In the notes this supports chrome v31-34. We are running chrome 33 so this is fine. We download the appropriate file for windows and extract the .exe to our Documents folder. The .exe can be placed where the user pleases but it must be in the system path. In this case we placed in the Documents folder namely :. This directory was added to the system path. We assume that a selenium server is also running if not one can be started using RSelenium::startServer() . Now we are done. A chrome browser can be controlled as follows: Internet Explorer. Similarly to the chrome browser you do not need to run an installer before using the InternetExplorerDriver, though some configuration is required. The standalone server executable must be downloaded from the Downloads page and placed in your PATH. Again we need to download this executable and place it in our path. At the time of writing the internet explorer .exe is included with the main standalone server here. The current release is 2.40. The system I am running is 64 bit so we download the 64bit version. For simplicity we again place this in our Documents directory namely C:. This directory is already in the system path from running the chrome example. If you want to place the internet explorer .exe in another folder add this folder to your system path. To control internet explorer as a browser is now as simple as: Safari. Currently Apple have discontinued developement of safari for windows. The latest version for windows was 5.1.7 available here. Starting with Selenium 2.30.0, the SafariDriver comes bundled with the Selenium server so nothing other then having safari installed should be required. For the purposes of this vignette I downloaded and installed safari 5.1.7 on a windows 8.1 system. Once installed controlling safari was as easy as: Opera. Opera is currently not supported for versions newer then 12. http://code.google.com/p/selenium/wiki/OperaDriver gives details on the current status. For the purposes of this vignette I downloaded and installed the 64 bit version of 12.16 located here. I had some issues getting this to run YMMV however. The first issue was getting the following error message. So not surprising win 8.1 was first unveiled and released as a public beta in June 2013 and on July 4, 2013, Opera 12.16 was released being the last current version of opera supported by selenium. OperaLauncherRunner.java located here does not currently cater for the WIN8 enum returned by Platform.getCurrent(). The solution is to start the selenium server with additional parameters passed to java (RSelenium::startServer doesn’t pass arguments to java atm) This is actually using java -D which is used to set a system property. The system property we set is os.name . This is nothing to do with selenium- server and the appearance of Dos is a coincidence not related to DOS. Now we get a new issue. So in this case we refer to the operadriver wiki. It states that the OperaDriver server expects you to have Opera or Opera Next installed in the default location for each system which for windows is %PROGRAMFILES%.exe or more precisely C:Files.exe. As I have installed the 64bit version I need to tell opera driver where to look. A few small issues. I suspect if you were running win 7 or lower and the 32 bit version of opera 12.16 it would probably run out of the box. RSelenium with Local Headless Browsers. Next we shall look at running what is known as headless browsers. Usually a browser can do three things. For given url, download the page (or any other content apart from html) Render the content into dom, eg executing inside the script tag. and the executed result will be reflected on the browsers dom. Render the dom into visualised content. A headless browser handles items 1 and 2 but doesn’t carryout 3. This means it doesn’t display anything. All pages etc. are in memory rather then displayed to the user. The result of this is that headless browsers should perform faster then their full-fledged competitors which could be welcome news to speed up testing. phantomjs. The first headless browser we shall look at is phantomjs . Firstly download the relevant zip file for your OS from here. We are using windows so we downloaded phantomjs-2.1.1-windows.zip. It is sufficient to place the location of the directory containing phantomjs.exe in your path. In this case we probably could have just extracted phantomjs.exe to the Documents folder where chromedriver etc current reside. However I extracted it to the desktop keeping the contents of the zip. The reasoning behind this was that phantomjs is driven by selenium using ghostdriver. At some point the version of ghostdriver phantomjs uses will be upgraded and will accept calls from an unexposed method phantomExecute of the RSelenium remoteDriver class. There are interesting scripts contained in the phantomjs /example directory like netsniff.js which captures network traffic in HAR format. When the phantomExecute method is exposed these scripts will be useful. So I added the location of the .exe to my path namely the directory C:-1.9.7-windows. Once your operating system can find phantomjs.exe or the equivalent driving a phantomjs browser is as easy as: We can take a screenshot even thou the browser is headless: RSelenium on win 8.1 driving phantomjs. PhantomJS is excellent. It has only recently as of version 1.8 had Ghost Driver integration and hopefully its importance will increase further. HtmlUnit. The original headless browser for selenium was . RSelenium with Local Mobile Browsers. Configuring your local machine to use mobile browsers can be slightly tricky. If you are having difficulty setting up on your particular OS you may want to skip this section. Android. The first mobile browser we will look at driving is Android. The selenium project had android drivers in the selenium project. The current state of these drivers is listed here. As can be noted driving android using the selenium server has been deprecated in favour of the selendroid project. Once selendroid has been setup this means that rather than running the selenium standalone jar as a server we will be running an equivalent selendroid jar to drive our browser on our real or emulated android phone. More on this later for now we will look at setting selendroid up. Setting up Selendroid. The selendroid project has a page on getting started. There are a couple of things to note Java SDK (minimum 1.6) must be installed . Most likely JRE is installed on your system. To check look for the directory C:Files1.7.0_51 or something similar. You can also check the version of java and it should indicate Java(TM) SE Runtime Environment . If you need the JDK you can install from here. Once the JDK is installed the environment variable JAVA_HOME should be set. Another Development kit needs to be installed SDK in this case. From the link provided you can download the ADT Bundle for Windows. I downloaded the bundle and extracted the zip to the Desktop this resulted in a directory C:\Users\john\Desktop\adt-bundle-windows-x86_64- 20131030 . There is a guide to setup the SDK here. The environment variable ANDROID_HOME needs to be set. This should be set to the /sdk/ directory in the extracted bundle. After setting ANDROID_HOME %ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools needs to be added to the system path also. Typing android in a command prompt should bring up the following: Android SDK on win 8.1. From the tools make sure all are installed. From the latest android release Android 4.4.2 (API 19) in this case make sure all are installed. From the Extras folder, select the checkbox for the Android Support Library and make sure it is installed. You will also want to install the Intel Hardware Accelerated Execution Manager. Instructions on how to do so are here. Basically checking the box Intel x86 Emulator Accelerator (HAXM) and “installing” will download it to %ANDROID_HOME%/extras/intel . In this folder is an exe IntelHaxm.exe which should be ran to finish the install. Creating an Android Virtual Device. Next we need to emulate a phone. The alternative is to use a hardware phone running the Android OS. Refer to here if you are running a hardware phone but it should be as simple as connecting it to the machine running selendroid via usb. We shall instead create an Android Virtual Device (Avd). The easiest way to do this is by typing android avd into a command console. Android AVD on win 8.1. You can see I have created an avd already named “my_avd”. You will need to create one by clicking new. The details for the “my_avd” are shown here. Android AVD my_avd on win 8.1. Click ok and an avd should have been created. You can start it using the panel. Click the newly created avd then click start. It will take a few moments but a panel containing a virtual phone will hopefully boot up and eventually get to the phone screen. Android AVD my_avd on win 8.1. If you have got to this point it is most likely you will now be able to drive this phone with selendroid. Take a few moments to play with your virtual android phone ;). Selendroid. Finally, we need to download the selendroid driver. The selendroid homepage has a link at the bottom to the most recent jar. This jar should be saved on the local computer. I saved the jar in the Documents folder namely C:\Users\john\Documents . To begin running tests you need to run the jar with java in a command prompt. RSelenium and Selendroid. Finally we are ready to use RSelenium to control an android browser. Android with RSelenium on win 8.1. Testing iOS requires a Mac. The setup is similar to selendroid. Appium and ios-driver can be used. An SDK is required namely iPhone simulator SDK and a virtual phone is ran in a similar fashion to Selendroid. RSelenium with Remote Browsers and External Sites. Setting up multiple OS/browsers combinations locally is not always the best use of ones time. It is an interesting exercise to implement for example an Android platform locally but the overhead of having multiple systems and browsers quickly overcomes the utility. There are professional service providers who maintain a suite of OS/browsers that can be utilised for testing. Companies such as ://saucelabs.com/ and http://www.browserstack.com offer free automated testing to open source projects. In this vignette we will demonstrate remote testing using Sauce Labs. Setting up Sauce Labs. We assume in this vignette that you are setting up Sauce Labs for an open source project. Firstly you should register your project here. On the account page you will find the access key for your account that is in a similar format to 49953c74-5c46-4ff9-b584-cf31a4c71809 . Using Sauce Labs is pretty straightforward. You need to tell it what OS/Browser combination you would like. A list of possible setups can be viewed here. As an example lets suppose we wished to run version 33 on OSX version mavericks. We state the browser and OS we require (chrome 33/ Mac OSX 10.9). The user and password are used to form an appropriate ip address for our remote server (http://rselenium0: [email protected] in this case). They are also passed as extraCapabilities to the remote Selenium server. We give our test a name and any additional tags we wish that are passed to the remote Selenium server. Details of the name and tags are given here. They are used to annotate our tests. Basic Example. As a basic first example we will run a script using the mavericks/ chrome 33 combination. We run the following commands: And that’s it. We have ran our first remote test using Sauce Labs. The results of the test can be viewed https://saucelabs.com/tests/ae22f859de8746f9bfedad2f49c1c329. I think you will agree its a nice setup. We have access to screenshots of all the commands we issued and a video (screencast) of the test run. We can view the selenium server logs and the medadata associated with our test. Testing Multiple OS/Browsers. We can easily extend the simple test we ran for multiple OS/Browser combinations. The browser and platform variables need to be assigned the combinations we require. To view the results you can goto the RSelenium project page on Sauce Labs https://saucelabs.com/u/rselenium. Listed here are all the tests ran on the RSelenium package. A partial search by name Browsers vignette first example will give the results of this test. There are a few repeats of the first Mavericks/ chrome 33 test where I tuned the script. Sauce Labs results for simple test script. RSelenium with Remote Browsers and Local Sites. Testing external webpages and websites across a range of operating systems and browsers can be achieved using Sauce Labs as we observed in the last section. Often however especially in a development phase of a project we either do not have or do not want an external version of our webpage/website/webapp. A good example would be our shinytestapp . Lets open a new R session and run our testapp. To access our app we would require the ip address http://localhost:3000/ . How do we access this from a remote webdriver? Sauce Connect. Thankfully Sauce Labs have a solution for this known as Sauce Connect. Sauce Connect is a secure tunneling app which allows you to execute tests securely when testing behind firewalls via a secure connection between Sauce Labs client cloud and your environment. This allows you to drive an external Browser and have it interact with a local webpage/website/webapp. Setting up Sauce Connect. Firstly you need to download the Sauce Connect zip for the operating system you are using to run your tests on. This machine I will be testing from is running windows 8.1 so I download the windows zip. I unzipped Sauce Connect to the Documents folder so it is now accessible at C:\Users\john\Documents\sc-4.1-win32 . From a windows command prompt we navigate to the Sauce Connect bin directory and run the .exe file supplying our Sauce Labs user name and access key. phantom : Start a phantomjs binary in webdriver mode. The name, full or partial path of a phantomjs executable. This is optional only state if the executable is not in your path. An integer giving the port on which phantomjs will listen. Defaults to 4444. format [[:]] An optional character vector: see 'Details'. Arguments to pass to system2. Details. phantom A utility function to control a phantomjs binary in webdriver mode. Detail. phantom() is used to start a phantomjs binary in webdriver mode. This can be used to drive a phantomjs binary on a machine without selenium server. Argument extras can be used to specify optional extra command line arguments see http://phantomjs.org/api/command-line.html. Value. phantom() returns a list with two functions: returns the process id of the phantomjs binary running in webdriver mode. RSelenium - Introduction. Selenium is actually composed of a number of projects (http://docs.seleniumhq.org/projects/). Selenium IDE Selenium Remote Control Selenium WebDriver Selenium Grid. Selenium WebDriver and Selenium Grid compose Selenium 2.0. Selenium 2.0. RSelenium interacts with the WebDriver The WebDriver "drives" the browsers. The browsers have various bindings Each browser may have bespoke methods. Firefox - The driver comes in the form of an xpi (firefox extension) Chrome - executable downloaded from the Chromium project which acts as a bridge between "chrome" and the "driver". IE - similar to chrome The SafariDriver is implemented as a Safari . RSelenium. Implements the JsonWireProtocol http://code.google.com/p/selenium/wiki/JsonWireProtocol Project page: https://github.com/johndharrison/RSelenium Issues: https://github.com/johndharrison/RSelenium/issues?state=open CRAN: http://cran.r- project.org/web/packages/RSelenium/index.html. Basic operation. Browser initiation Navigation DOM interaction Frames and Windows. Browser initiation. Navigation. DOM interaction. RSelenium has a number of methods of finding elements in the with two methods to search anchor elements (An anchor is a piece of text which marks the beginning and/or the end of a hypertext link.) Rselenium download phantomjs driver. This is a set of R Bindings for Selenium 2.0 Remote WebDriver, which you can download from http://selenium- release.storage.googleapis.com/index.html. This binding will not work with the 1.0 version of Selenium. Install. To install RSelenium from CRAN, run: To install the development version from GitHub, run: To get started using RSelenium you can look at the introduction vignette located in /doc/basics.html once RSelenium is installed or run. or the basic vignette can be viewed here. There is a second vignette dealing with running RSelenium on different browsers/OS locally and remotely which can be viewed at Driving OS/Browsers Local and Remote. Finally, you can read all about running a headless browser or running a normal browser on a headless server at Headless Browsing. Summary of Vignettes. Test Shiny Apps. Use RSelenium to test your Shiny Apps. Read the introductory tutorial here. Use Sauce Labs and BrowserStack. Sauce Labs. BrowserStack. Related Work. seleniumPipes: A lightweight implementation of the w3c webdriver specification. It has been built utilising xml2 , httr and magrittr so provides an alternative for users who are familiar with piping. webdriver: A client for the ‘WebDriver API’. It allows driving a (probably headless) , and can be used to test web applications, including Shiny apps. In theory it works with any ‘WebDriver’ implementation, but it was only tested with ‘PhantomJS’. rwebdriver: R bindings to the Webdriver API rdom: Render and parse the DOM from R via phantomjs. License. The RSelenium package is licensed under the AGPLv3. The help files are licensed under the creative commons attribution, non-commercial, share- alike license CC-NC-SA. As a summary, the AGPLv3 license requires, attribution, include copyright and license in copies of the software, state changes if you modify the code, and disclose all source code. Details are in the COPYING file.