我正在努力添加一个包含许多并发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,但正如你所看到的那样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}
答案 0 :(得分:4)
但是我面临以下问题: 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 app,它不支持-browser参数: unknown parameter unknown parameter 2
根据list of allowed phantomjs parameters,与5个并发的firefox实例相比,我设法只启动了1 phantom 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 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);
......
希望这适合你。
答案 1 :(得分:0)
我使用自己的Docker容器工作了: https://github.com/madhavajay/selenium-node-phantomjs
它使用PhantomJS 2.1.1自定义构建,然后我自己修改Ghostdriver以允许--remoteHost,以便Grid可以连接回Docker容器,无论它在哪个主机上。
我希望这有助于其他人。 :)
Docker Hub:madhavajay / selenium-node-phantomjs