使用PhantomJS在Selenium WebDriver中进行测试

时间:2017-07-12 16:55:50

标签: c# selenium selenium-webdriver phantomjs selenium-chromedriver

我正在尝试用Selenium WebDriver和PhantomJS编写一个简单的测试来简单地登录Reddit,并检查用户名是否等于页面上显示的用户名。我在使用ChromeDriver时进行了测试,但似乎无法使用PhantomJSDriver。有什么问题?

以下是我的一些代码:

private IWebDriver _driver;

[TestInitialize()]
public void MyTestInitialize()
{
    _driver = new PhantomJSDriver();
    _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
}

[TestMethod]
public void PhantomLogin()
{
    _driver.Navigate().GoToUrl(
    "http://reddit.com"
    );

    _driver.FindElement(By.Name("user")).SendKeys("{username}");
    _driver.FindElement(By.Name("passwd")).SendKeys("{password}");
    _driver.FindElement(By.ClassName("btn")).Click();

    WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
    wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(
    By.ClassName("logout")));

    Assert.AreEqual(
      "{username}",
      _driver.FindElement(By.ClassName("user")).FindElement(By.TagName("a")).GetAttribute("href").Split('/')[4]
    );
}

这是我得到的错误:

消息:测试方法PhantomDemo.UITests.Test.PhantomLogin抛出异常:OpenQA.Selenium.WebDriverException:对URL localhost的远程WebDriver服务器的HTTP请求:6114 / session / 88d4660-6723-11e7-8858- 2fa99172 / eleme nts在60秒后超时。 ---> System.Net.WebException:请求已中止:操作已超时。

编辑:添加了错误和更多代码

0 个答案:

没有答案