【问题标题】:Selenium grid node with many phantomjs concurrent instances具有许多 phantomjs 并发实例的 Selenium 网格节点
【发布时间】:2014-06-11 06:58:27
【问题描述】:

我正在努力添加一个具有许多并发 PhantomJS 实例的节点。在 GhostDriver github 页面上,您可以找到仅使用一个 PhantomJS 实例注册一个节点的说明:

phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444

我不允许发布图像,所以这是使用以下方法添加节点后的网格视图:

这里是配置标签内容:

port:6666
servlets:[]
host:null
cleanUpCycle:5000
browserTimeout:0
hubHost:127.0.0.1
registerCycle:5000
hub:http://127.0.0.1:4444/grid/register/
capabilityMatcher:org.openqa.grid.internal.utils.DefaultCapabilityMatcher
newSessionWaitTimeout:-1
url:http://127.0.0.1:6666
remoteHost:http://127.0.0.1:6666
prioritizer:null
register:true
throwOnCapabilityNotPresent:true
nodePolling:5000
proxy:org.openqa.grid.selenium.proxy.DefaultRemoteProxy
maxSession:1
role:wd
jettyMaxThreads:-1
hubPort:4444
timeout:300000

由于 selenium 网格允许从命令行定义节点浏览器,因此我尝试使用 phantomjs 来执行此操作,但您可以看到 here 不支持它。

-browser 允许的参数:browserName={android, chrome, firefox, htmlunit, internet explorer, iphone, opera} version={browser version} firefox_binary={path to executable binary} chrome_binary={path to executable binary} maxInstances ={该类型浏览器的最大数量} platform={WINDOWS, LINUX, MAC}

【问题讨论】:

    标签: selenium automated-tests phantomjs selenium-grid ghostdriver


    【解决方案1】:

    在同一个问题上苦苦挣扎: 我希望实现以下架构(下面的屏幕):

    但我面临以下问题: 1)如果我们使用以下参数配置 selenium-server-(在 UI 执行方式上配置,即通过 ffox、chrome 或 IE) 喜欢

    java -jar  selenium-server-standalone-2.41.0.jar -role node -hub htt
    p://localhost:4444/grid/register -port 7575 -browser  browserName=firefox,maxIns
    tances=5,platform=WINDOWS
    

    然后我们获得所需的结果:http://gyazo.com/6cd19155c78a59b22a09f4a3da3439b5 我想请您注意,使之成为可能的主要参数是: -browser browserName=firefox,maxInstances=5,platform=WINDOWS

    但是,例如 GhostDriver over phantomJs,我们预计不会启动 selenium-server-.jar 而是 phantomjs.exe 应用程序,它不支持 -browser 参数: unknown parameter unknown parameter 2

    根据list of allowed phantomjs parameters,与 5 个并发的 firefox 实例相比,我只启动了 1 phantom jsInstance

    这可能会对您有所帮助 - 现在我正在重新组织我的测试架构,并将尝试适应以下内容: 1 个节点 = 1 个 PhantomJs 实例。

    在 localhost 上,可以使用不同的端口运行许多节点(IE、Ffox、Chrome): http://gyazo.com/302fab9b6722251aa2cc6d98e2522931


    这个解决方案对我有用:

    • 关于项目结构的一些话: 我有 linux 机器(192.34.61.205,selenium hub 在这里运行)和大约 20 个与之相关的 phantomJs 节点: http://gyazo.com/0a3a50f2ee1638d10b1766e300438891 在所有节点上,phantomJs 作为服务运行(为了在节点上重新启动 phantomJs,只需输入命令sudo service phantomjs restart

    部分节点具有以下 IP: 162.243.175.134 162.243.175.97 162.243.175.252 ....

    public class BrowserOneInstance extends BaseMethodsForMultipleBrowsers {
    
        private WebDriver driver;
    
        private final static Logger log = LoggerFactory.getLogger(BrowserOneInstance.class);
        public static LoginPage loginPage;
        public static FacebookUserPage homePage;
    
        FileOperations fileManipulator = new FileOperations();
    
    
    //staring   hub - nodes model (on local WIN machine) over GhostDriver- pHantomJS
    
        @BeforeClass
        public void seleniumGrridUponGhostDriver() throws MalformedURLException {
    
    
    //        File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!
    
            File phantomjs = new File(System.getProperty("java.io.tmpdir")+File.separator+"phantomjs-1.9.7");
    
    
            DesiredCapabilities dcaps = new DesiredCapabilities();
            dcaps.setCapability("takesScreenshot", true);
    
    
            dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
    
    // !!!!! hardCoded initizliations of GhostDriver node
    //        driver = new RemoteWebDriver(new URL("http://localhost:8080"), dcaps);
    
    //    driver initialization   using  method  providing IP of running Ghost node connected to running hub
    //        this.driver= new RemoteWebDriver(new URL("http://"+getGhostNodesIp()+":8080"),dcaps);
    
    //        node  connected to linux hub:
            this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);
    
    
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    
            //page instances init()
            loginPage = PageFactory.initElements(driver, LoginPage.class);
            homePage = PageFactory.initElements(driver, FacebookUserPage.class);
        }
    
          @Test
     public void abracadabraTestMethod(){
    
      ....
     }
    
    
            @AfterTest
        public void driverTearDown() {
    //        close any of the instances: either Firefox or GhostDriver
            driver.quit();
        }
    
    }
    

    注意:

    如果您想让 phantomJs 以跨平台方式工作,则无需手动替换 你可以使用 Phanbedder - PhantomJS Windows/Mac OS X/Linux native binary embedder:

    import net.anthavio.phanbedder.Phanbedder;
    
    ......
    
     @BeforeClass
        public void seleniumGrridUponGhostDriver() throws MalformedURLException {
    
            File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!
    
    
            DesiredCapabilities dcaps = new DesiredCapabilities();
            dcaps.setCapability("takesScreenshot", true);
    
    
            dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
    
    
            this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);
    
    ......
    

    希望这对你有用。

    【讨论】:

    • 你得到结果了吗? :)
    • 是的,设法让它工作。将在几个小时内提供代码。
    • 您是通过 selenium 网格启动它吗?或者只是没有 selenium 服务器的 phantomjs / ghost 驱动程序的个别瞬间?
    • @eugene.polschikov:嗨!我想问你关于在一个节点上运行 5 个 GhostDriver 的实例——这可能吗?问题已经解决了吗?谢谢。
    【解决方案2】:

    我使用我自己的 Docker 容器进行了这项工作: https://github.com/madhavajay/selenium-node-phantomjs

    它使用 PhantomJS 2.1.1 自定义构建,然后我自己对 Ghostdriver 进行修改以允许 --remoteHost 以便 Grid 可以连接回 Docker 容器,无论它位于哪个主机上。

    我希望这对其他人有所帮助。 :)

    Docker 中心:madhavajay/selenium-node-phantomjs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-06
      • 2018-05-28
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多