【发布时间】:2016-02-08 12:38:32
【问题描述】:
我正在编写一个自动化脚本来测试网站登录。通过 Firefox IDE,我编写了 TestCase 步骤,它执行得很好。我将测试用例导出为与 jUnit 4 兼容的 java 代码。
当我尝试通过 Eclipse(使用 firefox 浏览器)运行 java 代码时,它会打开 Mozilla 主页或空白页面或代理问题(如果我的机器连接到公司 LAN)。
我正在使用 Selenium 2.44 和 Firefox 版本 44.. 我还在一些网站上读到了有关与 selenium web 驱动程序兼容的 firefox 版本。我对此感到很困惑。
请告诉我首选哪个版本的 Selenium Web 驱动程序、Firefox 和 Java..!!!
在下面添加我的java代码
public class Firefox {
private WebDriver driver;
private String PROXY = "proxy address:port";
private String baseUrl;
private boolean acceptNextAlert = true;
@Before
public void setUp() throws Exception {
// Code for setting up Firefox proxy
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
baseUrl = "url";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testFirefox() throws Exception {
driver.get(baseUrl);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if ("".equals(driver.findElement(By.id("userId")).getText())) break;
}
catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("userId")).sendKeys("user name");
driver.findElement(By.id("pwd")).sendKeys("password");
driver.findElement(By.id("sign-in")).click();
}
}
【问题讨论】:
-
显示您的代码,您在公司局域网中使用代理服务器吗?
-
'代理 proxy = new org.openqa.selenium.Proxy(); proxy.setHttpProxy(proxyadrs) .setFtpProxy(proxyadrs) .setSslProxy(proxyadrs); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY,代理); driver = new FirefoxDriver(cap);'
-
这是我正在使用的代码.. 但这永远不会改变 firefox 代理的详细信息。 firefox 总是指向系统设置..
-
我看到 Selenium 2.44 的更新日志显示
* Updating Native events to support Firefox 24, 31, 32 and 33,所以你可能应该使用最新版本的 Selenium -
在 Selenium 2.51 的更新日志中提到的 Firefox 的最新版本是 39。所以试试 Selenium 2.51 和 Firefox v. 39
标签: java eclipse junit4 selenium-firefoxdriver