从R或python运行yaml文件进行并行硒测试 [英] Run yaml file for parallel selenium test from R or python

查看:105
本文介绍了从R或python运行yaml文件进行并行硒测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Yaml文件:

I have a simple yaml file:

seleniumhub:
    image: selenium/hub
    ports:
      - 4444:4444

firefoxnode:
    image: selenium/node-firefox-debug
    ports:
      - 4577
    links:
      - seleniumhub:hub

chromenode:
    image: selenium/node-chrome-debug
    ports:
      - 4578
    links:
      - seleniumhub:hub

我已经在docker中执行过的

that I have executed in docker:

docker-compose up -d

我有一个集线器和两个节点在运行。

I have one hub and two nodes running.

现在,我想并行运行两个非常简单的selenium命令(用RSelenium编写):

Now I would like to run two very simple selenium commands in parallel (written in RSelenium):

remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)

我想知道如何在硒命令中运行Python或R,并行执行。我尝试了几种方法,但没有任何效果。例如在R中:

I would like to know how can I run above selenium commands in Python or R, in parallel. I tried several ways but none works. For example in R:

library(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4444L)
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)

不执行任何操作。我也尝试过运行两个remoteDrivers,但这对以太坊没有帮助:

doesn't do anything. I have also tried to run two remoteDrivers, but that doesn't help ether:

remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4577L)
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)


推荐答案

这是

并行运行RSelenium

您可以使用以上答案中的代码进行并行执行

You can use code in above answer to do parallel execution

library(RSelenium)
library(rvest)
library(magrittr)
library(foreach)
library(doParallel)

URLsPar <- c("http://www.bbc.com/", "http://www.cnn.com", "http://www.google.com",
             "http://www.yahoo.com", "http://www.twitter.com")
appHTML <- c()

(cl <- (detectCores() - 1) %>%  makeCluster) %>% registerDoParallel
# open a remoteDriver for each node on the cluster
clusterEvalQ(cl, {
  library(RSelenium)
  remDr <- remoteDriver$new(remoteServerAddr = ip, port = port)
  remDr$open()
})
myTitles <- c()
ws <- foreach(x = 1:length(URLsPar), .packages = c("rvest", "magrittr", "RSelenium"))  %dopar%  {
  remDr$navigate(URLsPar[x])
  remDr$getTitle()[[1]]
}

# close browser on each node
clusterEvalQ(cl, {
  remDr$close()
})

stopImplicitCluster()

这篇关于从R或python运行yaml文件进行并行硒测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆