---
title: "OCRUG Webinar"
author: "John Harrison"
date: "22 MAY 2014"
output:
  html_vignette:
    toc: yes
vignette: >
  %\VignetteIndexEntry{OCRUG Webinar}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

Yesterday I gave a webinar on the [Rselenium](https://github.com/johndharrison/RSelenium) package to the OC-RUG. When I published RSelenium on CRAN Ray DiGiacomo the president of OC-RUG was kind enough to invite me to present RSelenium and that webinar was held on the 21st of May. I would like to thank OC-RUG and Ray in particular for the opportunity.

I will use this blog to present the video of the webinar and also for a bit of bookkeeeping. Firstly I would like to return to two of the questions asked in the Q&A.


## Q&A Question 2 and 3

### How Would You Save a Screenshot to File Using RSelenium?

In the seminar I suggested that the Selenium webdriver returned the png in a  base 64 encoded format. I tried to save the output to file using `writeBin` and remarked that I probably needed to decode the output. So here is what I should have done:

```R
b64out <- remDr$screenshot()
writeBin(base64Decode(b64out, "raw"), 'nameoffile.png')
```

### How Would You Use a Chrome Profile?

In the seminar I remarked that the google chrome browser had hundreds of startup options. They are actually termed [command line switches](http://peter.sh/experiments/chromium-command-line-switches). The two I was after were `--user-data-dir` and `--profile-directory`. It would then have been sufficient to use:

```R
args = list(
  paste0('--user-data-dir=',dataDir),
  paste0('--profile-directory=',profileDir)
)
cprof <- list(chromeOptions = list(args = args))
remDr <- remoteDriver(
  browserName = 'chrome',
  extraCapabilities = cprof
)
```

### Added to RSelenium

I added the above functionality to RSelenium. So now the `screenshot` method of the `remoteDriver` class has an optional `file` argument. If `display` is `FALSE` and a `file` argument is given `RSelenium` will now save the `png` to file.

Secondly there is now a `getChromeProfile` utility function in a similar vein to the existing getFirefoxProfile function. The function is documented in the RSelenium package. Its basic usage is as follows:

```R
# example from windows using a profile directory "Profile 1"
dataDir <- "C:\\Users\\john\\AppData\\Local\\Google\\Chrome\\User Data"
cprof <- getChromeProfile(dataDir, "Profile 1")
remDr <- remoteDriver(browserName = "chrome", extraCapabilities = cprof)
```

So it takes two arguments: a users chrome data directory and the profile directory within that data directory from which you want to run.

I will update the version of `RSelenium` on CRAN in the coming weeks. If you would like to run the dev version with added features you can install it with:
  
```R
devtools::install_github("johndharrison/RSelenium")
```

and remember to file any issues you may have. to github so `RSelenium` can improve as a package :).


## The Webinar Screencast

<iframe width="653" height="480" src="https://www.youtube.com/embed/ic65SWRWrKA" frameborder="0" allowfullscreen></iframe>


### SauceLabs Test Results

At the end of the webinar the simple test on the shinytestapp was ran against multiple OS and browsers using Sauce Labs as an external provider for the selenium server and the browsers. These test results can be seen bu navigating to the RSelenium Sauce Labs page [https://saucelabs.com/u/rselenium0](https://saucelabs.com/u/rselenium0) and searching for `OCRUG TEST 1` in the search session name panel.


## The Directors Cut

I have shot an extended version of the webinar with the fabled missing `javascript` example which follows:

<iframe width="653" height="480" src="https://www.youtube.com/embed/zcUGla8EjjY" frameborder="0" allowfullscreen></iframe>


## The Slides and R Scripts

And finally I have posted the slides for the webinar to github. Please find them at [http://johndharrison.github.io/RSOCRUG](http://johndharrison.github.io/RSOCRUG). There are also some R scripts contained in the master branch of the github project: https://github.com/johndharrison/RSOCRUG


## Conclusion

Hopefully that ties up any loose ends. It was great fun preparing the webinar. I enjoyed giving it and I'm gratefully to everyone who attended.
