在同一个问题上苦苦挣扎:
我希望实现以下架构(下面的屏幕):
但我面临以下问题:
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
这个解决方案对我有用:
部分节点具有以下 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);
......
希望这对你有用。