Java构造函数参数Selenium与WebDriverBackedSelenium
我正在使用旧版本的自动化脚本,该脚本登录到页面并运行测试。Java构造函数参数Selenium与WebDriverBackedSelenium
我们希望将经典的硒构造函数更改为WebDriverBackedSelenium构造函数,以便执行更多的涉及测试。
我们原来的构造函数的调用是:
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://asdffdsa.com/");
如何设置使用相同参数的构造函数WebDriverBackedSelenium?该API表明,我们需要设置的构造为:
seWebDriver = new WebDriverBackedSelenium(driver, "https://asdffdsa.com");
似乎有不为大约在硒服务器运行,哪个端口的任何指示,什么浏览器。
目前使用下面的代码:
driver = new FirefoxDriver();
seWebDriver = new WebDriverBackedSelenium(driver, "https://www.asdfdfdfsfs.com");
seWebDriver.open("/");
刚才注意到,我得到了以下错误:
造成的:org.openqa.selenium.firefox.NotConnectedException:无法连接到45000毫秒后,端口7055上的主机127.0.0.1。 Firefox的控制台输出: * LOG addons.manager:应用程序已经升级 LOG addons.xpi:启动 LOG addons.xpi:跳绳不可用安装位置的应用系统共享 LOG addons.xpi:忽略文件项的名称不是有效的附加ID:在/ var /文件夹/ PF/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous2501560210712840923webdriver-资料/扩展/ webdriver的-分期 LOG addons.xpi:checkForChanges LOG addons.xpi -utils:打开数据库 LOG addons.xpi-utils的:创建数据库模式 LOG addons.xpi:新增加的[email protected]安装在应用程序瞩目 阻止列表:: _ loadBlocklistFromFile:黑名单禁止 LOG插件的.xpi:新增加的{972ce4c6-7e08-4474-a285-3208198ce6fd}安装应用程序,全球 LOG addons.xpi:更新数据库更改安装的插件 LOG addons.xpi-utils的:更新附加状态 LOG addons.xpi- utils的:编写插件列表 LOG addons.manager:关机 LOG addons.xpi:关机 LOG addons.xpi-utils的:关机 LOG addons.xpi-utils的:数据库关闭 LOG addons.xpi:启动 LOG addons.xpi:跳过不可用的安装位置app-system-share LOG插件。XPI:忽略文件项的名称不是有效的附加ID:在/ var /文件夹/ PF/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous2501560210712840923webdriver-资料/扩展/ webdriver的-分期 LOG addons.xpi:checkForChanges * LOG插件.xpi:未找到更改
以下是使用Webdriver备份硒的示例。
使用webdriverbacked Selenium时不需要提及端口号。
在下面的程序中,对象Selenium
用于利用Selenium RC(您的旧自动化脚本构造函数)的属性。
对象driver
是为了利用Webdriver(Selenium2.0)的功能。
public class BackedWebdriver {
public static WebDriver driver;
public static String baseUrl;
public static Selenium selenium;
public static void main(String[] args) {
driver = new FirefoxDriver(); //Here we are mentioning that we will use Firefox browser
baseUrl = "http://www.google.co.in/";
driver.get(baseUrl);
selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.windowMaximize();
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("selenium");
selenium.click("g");
driver.findElement(By.id("gbqfb")).click();
}
我认为我们需要WebDriver在这个自动化中的功能,但是当我设置它并将它作为UnitTest运行时,它试图加载localhost,而不是我在构造函数中给它的网站。 – 2013-03-06 21:25:48
你使用的是driver.get(url)还是selenium.open(url)? 如果您可以分享代码,这将有所帮助。 – Hemanth 2013-03-07 05:06:01
selenium.open(url)代码是一团糟我试着清理一下它,然后发布相关的部分。 – 2013-03-07 19:06:21
DesiredCapabilities ffLinux = DesiredCapabilities.firefox();
ffLinux.setBrowserName("firefox");
ffLinux.setPlatform(Platform.LINUX);
String hubLocation = http://yourmachine.com:4444/wd/hub;
WebDriver driver = new RemoteWebDriver(hubLocation, ffLinux);
driver.get(yourWebApplicationURLThatsBeingTested);
在你上面的例子与WebDriverBackedSelenium,你传递的第一个参数是“司机”。看看我如何设置我的WebDriver上面:它指定了枢纽位置。
老兄,看看我下面的答案。而不是使用driver = new FirefoxDriver()使用驱动程序=新的RemoteWebDriver(集线器,功能),其中hub类似于http:// localhost:4444/wd/hub。我不明白你为什么在我已经提供答案时编辑这个问题。另外,硒文档非常好,所有这些东西都在那里回答。 – KyleM 2013-03-07 21:37:51
上面列出的错误是由于版本化incomaptibilities或某事。请参阅http://*.com/questions/10013898/unable-to-connect-to-host-127-0-0-1-on-port-7055了解更多信息。 – 2013-03-08 18:54:27