John Harrison (johndharrison0@gmail.com)
Selenium is actually composed of a number of projects (http://docs.seleniumhq.org/projects/).
Selenium WebDriver and Selenium Grid compose Selenium 2.0.
RSelenium interacts with the WebDriver | |
The WebDriver "drives" the browsers. | |
The browsers have various bindings | |
Each browser may have bespoke methods |
# RSelenium::startServer()
library(RSelenium)
remDr <- remoteDriver(browserName = "someBrowser", remoteServerAddr = ip, port = port)
remDr$open(silent = TRUE)
remDr$navigate("http://somecoolsite")
Browser | Sessions | % Sessions | |
---|---|---|---|
1. | Chrome | 135 | 45.76% |
2. | Firefox | 111 | 37.63% |
3. | Safari | 29 | 9.83% |
4. | Internet Explorer | 12 | 4.07% |
5. | Opera | 3 | 1.02% |
6. | Safari (in-app) | 3 | 1.02% |
7. | Android Browser | 2 | 0.68% |
remDr$Navigate("http://somewhere.com")
remDr$goBack()
remDr$goForward()
remDr$refresh()
remDr$getTitle()
remDr$getCurrentUrl()
remDr$getStatus()
remDr$getAllCookies()
remDr$deleteCookieNamed("PREF")
RSelenium has a number of methods of finding elements in the document object model 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.)
remDr$switchToFrame("string|number|null|WebElement")
remDr$getWindowHandles()
remDr$getCurrentWindowHandle()
remDr$switchToWindow("windowId")
Dialect Map http://spark.rstudio.com/jkatz/SurveyMaps/ If I remember rightly this one went viral was viewed 7 million times and crashed rstudios server.
RSelenium test app Viewable at http://spark.rstudio.com/johnharrison/shinytestapp/ or can be ran from the Rselenium package locally.
(http://johndharrison.blogspot.co.uk/2014/03/rstudioshiny-server-on-digital-ocean.html)
remDr <- remoteDriver(remoteServerAddr = "128.199.255.233", browserName = 'phantomjs')
remDr$open()
remDr$navigate("http://whatismyipaddress.com/")
remDr$screenshot(display = TRUE)
remDr$close(); remDr$closeServer()
Sauce Labs - http://saucelabs.com/
user <- "rselenium0"
pass <- "*******************************"
port <- 80
ip <- paste0(user, ':', pass, "@ondemand.saucelabs.com")
browser <- "firefox"
version <- "25"
platform <- "OS X 10.9"
extraCapabilities <- list(name = "Test RSelenium", username = user, accessKey = pass)
remDr <- remoteDriver$new(remoteServerAddr = ip, port = port, browserName = browser
, version = version, platform = platform
, extraCapabilities = extraCapabilities)
Browser Stack - http://www.browserstack.com/
require(RSelenium)
user <- "johnharrison"
pass <- "******************"
port <- 80
ip <- paste0(user, ':', pass, "@hub.browserstack.com")
extraCapabilities <- list("browser" = "IE",
"browser_version" = "7.0",
"os" = "Windows",
"os_version" = "XP",
"browserstack.debug" = "true")
remDr <- remoteDriver$new(remoteServerAddr = ip, port = port
, extraCapabilities = extraCapabilities)
testAppScript <- function(remDr){
remDr$open(); remDr$setImplicitWaitTimeout(2000)
remDr$navigate("http://spark.rstudio.com/johnharrison/shinytestapp/")
Sys.sleep(2)
webElems <- remDr$findElements("css selector", "#ctrlSelect span")
lapply(webElems, function(x){x$highlightElement()})
Sys.sleep(2)
appIds <- c("summary", "distPlot", "ggPlot", "dttable")
lapply(seq_along(webElems), function(x){
if(!webElems[[x]]$isElementSelected()[[1]]){
webElems[[x]]$clickElement()
# test for its output
out <- remDr$findElement("id", appIds[x])
out$highlightElement()
}})
remDr$close()
}
testAppScript(remDr)