driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(URL);
我尝试使用版本46.0.1和webdriver 2.53.0在Firefox中运行我的测试但是当我运行测试时,我看到Firefox启动然后很快关闭。我已经让所有其他浏览器都能正常工作,并且对我在这里失踪的内容感到茫然。
@BeforeClass
public static void setUp() {
System.out.println("****************");
System.out.println("launching Browser");
driver = new FirefoxDriver();
driver.get("url");
@Test
public void testPageTitleInBrowser() {
FirstPage firstPage = PageFactory.initElements(driver,FirstPage.class); 第一页
.logIn(username, password)
.clickHolidayLink()
.completeHolidayFormAndSubmit("12/05/2016");
}
@AfterClass
public static void tearDown() {
if (driver != null) {
System.out.println("Closing browser");
driver.quit();
}
}
主页已更改为首页
import com.google.common.annotations.VisibleForTesting;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import static Internal.BaseTest.driver;
public class FirstPage {
@VisibleForTesting
@FindBy(id = "ctl00_MCPH_MainLogin_UserNameTextBox")
WebElement usernameInput;
@VisibleForTesting
@FindBy(id = "ctl00_MCPH_MainLogin_PasswordTextBox")
WebElement passwordInput;
@VisibleForTesting
@FindBy(id = "ctl00_MCPH_MainLogin_LoginButton")
WebElement loginButton;
public BookAHoliday logIn(String username, String password){
usernameInput.sendKeys(username);
passwordInput.sendKeys(password);
loginButton.click();
return PageFactory.initElements(driver, BookAHoliday.class);
}
}
答案 0 :(得分:1)
由于上面的代码片段中没有编写测试用例,因此@BeforeClass
将打开firefox驱动程序,并且driver != null
满足条件@AfterClass
,firefox将关闭。根据您的代码,这是预期的行为。
答案 1 :(得分:0)
在Thread.sleep(3000);
之前添加driver.quit();
或删除driver.quit();
,看看会发生什么。由于您在测试中没有做太多工作,因此可能表现正常。
答案 2 :(得分:0)
我遇到了类似的问题。 Firefox将打开然后关闭,甚至没有导航到指定的URL。升级到最新的selenium(2.53)解决了这个问题。
还有另一个例子,即使升级也没有用。这是由于我的组织安装了一些插件。
暂时重命名安装Firefox所在位置的“分发”目录,看看是否有效。例如:C:\Program Files (x86)\Mozilla Firefox\
或/usr/lib/firefox/
这对我有用。