![](/img/trans.png)
[英]Selenium Grid Concurrent Execution: How many concurrent browsers per node?
[英]Selenium grid node with many phantomjs concurrent instances
我很難添加一個包含許多並發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 grid允許從命令行定義節點瀏覽器,我嘗試使用phantomjs,但正如你在這里看到的那樣,它不受支持。
參數允許-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 = {maximum這種類型的瀏覽器數量} platform = {WINDOWS,LINUX,MAC}
苦苦掙扎同樣的問題:我期望實現以下架構(下面的屏幕):
但是我面臨以下問題: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超過phantomJs,我們預計不會啟動selenium-server-.jar而是phantomjs.exe應用程序,它不支持-browser參數: 未知參數 未知參數2
根據允許的phantomjs參數列表,與5個並發的firefox實例相比,我設法只啟動了1個幻像jsInstance 。
可能對你有所幫助 - 現在我正在重新設計我的測試架構,並嘗試調整以下內容:1 NODE = 1個PhantomJs實例。
在localhost上可以使用不同的端口運行許多節點(IE,Ffox,Chrome): http ://gyazo.com/302fab9b6722251aa2cc6d98e2522931
這個解決方案對我有用:
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本機二進制嵌入器 :
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);
......
希望這對你有用。
我使用自己的Docker容器工作: https : //github.com/madhavajay/selenium-node-phantomjs
它使用PhantomJS 2.1.1自定義構建,然后我自己修改Ghostdriver以允許--remoteHost,以便Grid可以連接回Docker容器,無論它在哪個主機上。
我希望這有助於其他人。 :)
Docker Hub:madhavajay / selenium-node-phantomjs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.