-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-rstudio.R
69 lines (54 loc) · 1.84 KB
/
test-rstudio.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if (!exists("context_of")) source("initialize.R")
pageURL <- paste0(site_url, "/rstudio/start.view?")
context_of(
file = "test-rstudio.R",
what = "RStudio",
url = pageURL
)
test_connection(remDr, pageURL, "Launch RStudio")
test_open <- function(button) {
expect_equal(button[[1]]$getElementText()[[1]], "Open RStudio Server")
# open rstudio server
button[[1]]$clickElement()
sleep_for(5)
tabs <- remDr$getWindowHandles()
expect_equal(length(tabs), 2, info = "Couldn't open RStudio Server")
if (length(tabs) == 2) {
# switch to rstudio tab
remDr$switchToWindow(tabs[[2]])
expect_match(remDr$getTitle()[[1]], "^RStudio")
if (grepl("^RStudio", remDr$getTitle()[[1]])) {
# close rstudio tab
remDr$closeWindow()
# switchback to test tab
remDr$switchToWindow(tabs[[1]])
expect_equal(remDr$getTitle()[[1]], "Launch RStudio")
}
}
}
test_that("'RStudio' is working", {
module <- remDr$findElements(using = "css selector", value = "div.lk-body-ct")
expect_equal(length(module), 1)
if (length(module) == 1) {
button <- module[[1]]$findChildElements(using = "css selector", value = "a.labkey-button")
expect_equal(length(button), 1)
if (length(button) == 1) {
buttonText <- button[[1]]$getElementText()[[1]]
if (buttonText == "Start RStudio Server") {
# start rstudio server
button[[1]]$clickElement()
# launching
sleep_for(5)
# loaded
module <- remDr$findElements(using = "css selector", value = "div.lk-body-ct")
button <- module[[1]]$findChildElements(using = "css selector", value = "a.labkey-button")
expect_equal(length(button), 1, info = "Couldn't start RStudio Server")
if (length(button) == 1) {
test_open(button)
}
} else {
test_open(button)
}
}
}
})