Skip to content

Commit

Permalink
Fisrt Ever Fix for ChromeDriver + wdman issue
Browse files Browse the repository at this point in the history
Selenium 4.8 compatibility yet to be tested
  • Loading branch information
bedantaguru committed Feb 10, 2023
1 parent fc31ae3 commit 244aebb
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Suggests:
testthat
11 changes: 9 additions & 2 deletions R/RSeleniumTools_core.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ web_automation_platform <- function(
#' web control client
#'
#' @export
web_control_client <- function(){
web_control_client <- function(browser, force_new = FALSE){

# check prior saved client

if(exists("web_control_client_cache",envir = rst_wap_env)){
if(exists("web_control_client_cache",envir = rst_wap_env) & !force_new){
rd <- rst_wap_env$web_control_client_cache
if(rst_remotedriver_check(rd)){
return(invisible(rd))
Expand All @@ -227,6 +227,13 @@ web_control_client <- function(){
shared_config <- ws$read("wap_rst_client_config", R_object = TRUE)
if(is.null(shared_config)) shared_config <- list()

if(!missing(browser)){
# this is required to be developed as expected
#@Dev
#TODO
shared_config$browser <- browser
}

rd <- do.call("rst_remotedriver", args = shared_config)
if(is.null(psid)){
# this means fresh sid need to be generated
Expand Down
79 changes: 49 additions & 30 deletions R/RSeleniumTools_wdman.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ rst_wdman_selenium_fill_info_env <- function(spid, pmap, full_control = TRUE){
}

rst_wdman_selenium_launcher <- function(
port = NULL,
selenium_version = c("dev","stable"),
on_exit_cleanup = FALSE,
# -browserTimeout
# <Integer> in seconds : number of seconds a browser session is allowed to
# hang while a WebDriver command is running (example: driver.get(url)). If
# the timeout is reached while a WebDriver command is still processing,
# the session will quit. Minimum value is 60. An unspecified, zero, or
# negative value means wait indefinitely. If a node does not specify it,
# the hub value will be used.
browserTimeout = 300L,
# -timeout, -sessionTimeout
# <Integer> in seconds : Specifies the timeout before the server
# automatically kills a session that hasn't had any activity in the last X
# seconds. The test slot will then be released for another test to use.
# This is typically used to take care of client crashes. For grid hub/node
# roles, cleanUpCycle must also be set. If a node does not specify it, the
# hub value will be used.
#
# ref : https://stackoverflow.com/questions/55438913/is-there-a-way-too-prevent-selenium-automatically-terminating-idle-sessions
sessionTimeout = 57868143L,

webdrivers_offline
port = NULL,
selenium_version = c("dev","stable"),
on_exit_cleanup = FALSE,
# -browserTimeout
# <Integer> in seconds : number of seconds a browser session is allowed to
# hang while a WebDriver command is running (example: driver.get(url)). If
# the timeout is reached while a WebDriver command is still processing,
# the session will quit. Minimum value is 60. An unspecified, zero, or
# negative value means wait indefinitely. If a node does not specify it,
# the hub value will be used.
browserTimeout = 300L,
# -timeout, -sessionTimeout
# <Integer> in seconds : Specifies the timeout before the server
# automatically kills a session that hasn't had any activity in the last X
# seconds. The test slot will then be released for another test to use.
# This is typically used to take care of client crashes. For grid hub/node
# roles, cleanUpCycle must also be set. If a node does not specify it, the
# hub value will be used.
#
# ref : https://stackoverflow.com/questions/55438913/is-there-a-way-too-prevent-selenium-automatically-terminating-idle-sessions
sessionTimeout = 57868143L,

webdrivers_offline
){

selenium_version <- match.arg(selenium_version)
Expand Down Expand Up @@ -117,23 +117,42 @@ rst_wdman_selenium_launcher <- function(
selargs_lst$sessionTimeout <- paste0("-sessionTimeout ",
as.integer(sessionTimeout ))

# this is required for fix in "wdman and LICENSE.chromedriver issue"
bypass_wdman_detection <- TRUE
extra_jvmargs_lst <- list()

# chrome
cver <- NULL
if("chromedriver" %in% webdrivers_offline$appname){
cver <- webdrivers_offline$version[
webdrivers_offline$appname=="chromedriver"
]
if(bypass_wdman_detection){
cexe <- webdrivers_offline$bin_file[
webdrivers_offline$appname=="chromedriver"
]
extra_jvmargs_lst$chrome <- paste0(
"-Dwebdriver.chrome.driver=",
paste0('"',cexe,'"')
)
}else{
cver <- webdrivers_offline$version[
webdrivers_offline$appname=="chromedriver"
]
}
}

# gecko (firefox)
gver <- NULL
if("geckodriver" %in% webdrivers_offline$appname){
gver <- webdrivers_offline$version[
webdrivers_offline$appname=="geckodriver"
]
if(bypass_wdman_detection){

stop("To Develop")

}else{
gver <- webdrivers_offline$version[
webdrivers_offline$appname=="geckodriver"
]
}
}

extra_jvmargs_lst <- list()

# opera
if("operadriver" %in% webdrivers_offline$appname){
Expand Down
49 changes: 49 additions & 0 deletions R/RSeleniumTools_webdrivers_specifics.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ rst_webdriver_specific_opera <- function(over, offline_info = NULL){
# technically it is not webdriver (it is selenium itself)
# sver can be stable, dev, both
rst_webdriver_specific_selenium <- function(sver = "both", offline_info = NULL){
# this is full obsolete
#TODO fix it for Selenium 4.8

sver <- match.arg(sver, choices = c("both","dev","stable"))

Expand Down Expand Up @@ -326,6 +328,8 @@ rst_webdriver_specific_selenium <- function(sver = "both", offline_info = NULL){
stablev <- numeric_version("3.141.59")

if(!do_offline){
# very very bad approach need to clean up
#TODO
tryCatch({
# try to update
wc <- readLines("https://www.selenium.dev/downloads/", warn = FALSE)
Expand Down Expand Up @@ -391,3 +395,48 @@ rst_webdriver_specific_selenium <- function(sver = "both", offline_info = NULL){


}

#@Dev
#TODO
# new development for selenium 4.8
rst_webdriver_specific_selenium_2023 <- function(sver = "new", offline_info = NULL){


info <- list(
driver_url =
"https://api.github.com/repos/SeleniumHQ/selenium/releases",
compatibility =
"https://www.selenium.dev/"
)

do_offline <- FALSE
#TODO

if(do_offline){
stop("TODO")
#driver_web_info <- rst_webdriver_url_parser(offline_info, offline = TRUE)
}else{
driver_web_info <- rst_webdriver_url_parser(info$driver_url)
}

driver_web_info$core <- driver_web_info$core[
driver_web_info$core$appname == "selenium",
]

driver_web_info$core$appname_based_on_filename <-
sub("-[0-9alphabetarc.-]+.jar$","",driver_web_info$core$file)

driver_web_info$core <- driver_web_info$core[
driver_web_info$core$appname_based_on_filename == "selenium-server",
]
# early exit
if(nrow(driver_web_info$core)==0) return(NULL)

# pick the latest
driver_web_info$core$for_this_browser <-
driver_web_info$core$time_idx==max(driver_web_info$core$time_idx)

rst_webdriver_specific_finalizer(driver_web_info, info)


}
22 changes: 22 additions & 0 deletions inst/embedded/known_issue_fix_implementer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


# this file attempts to fix several issues on the fly
# this is like community driven hot fixes

############# Fix for ###############
#######
####### RSelenium - and related packages
#######
#####################################

# Issue 1
# wdman and LICENSE.chromedriver issue
# this can be handled directly in rst_wdman_selenium_launcher
# <><> Fixed


# Issue 2
# wdman expects only "selenium-server-standalone" selenium-server will not work
#TODO many works may be required here
# main issue RSelenium is not working as of now with selenium 4.8
# need to add flag standalone in command
3 changes: 2 additions & 1 deletion man/web_automation_platform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 244aebb

Please sign in to comment.