【问题标题】:Second testMethod failing Selenium C#第二个测试方法失败 Selenium C#
【发布时间】:2012-04-13 14:36:57
【问题描述】:

这是我的代码:

[TestInitialize]
    public void init()
    {
        _browser = new DefaultSelenium("localhost", 4444, @"*iehta", "http://localhost:4444");
    }


    [TestMethod]
    public  void TestLogin()
    {
        bool hasText;


        _browser.Start();

        _browser.Open("http://localhost/testSite.asp");
        _browser.Type("id=NomUtilisateur", "admin");
        _browser.Type("id=UserPassword", "password");
        _browser.Click("name=Submit");
        _browser.WaitForPageToLoad("30000");
        hasText = _browser.IsTextPresent("test");

        Assert.IsTrue(hasText, @"The search result does not contain text ""test"".");




    }
    [TestMethod]
    public void TestRequisitionPhotocopie()
    {

        _browser.Start();
        _browser.Open("http://localhost/testSite.asp");
        _browser.Type("id=NomUtilisateur", "admin");
        _browser.Type("id=UserPassword", "password");
        _browser.Click("name=Submit");
        _browser.WaitForPageToLoad("30000");
        _browser.Click("link=lnkTest");
        _browser.WaitForPageToLoad("30000");


    }
    [TestCleanup]
    public void clean()
    {
        _browser.Stop();
        //_browser.Close();
    }

如果我运行这两种测试方法,第二次测试总是失败并显示如下错误消息: 远程服务器不存在或不可用

如果我评论其中一种测试方法,它正在工作,我的两种测试方法正在工作

我的错在哪里。

谢谢

编辑: 错误并非每次都发生,但错误出现在 Selenium 远程控制中

Selenium 日志控制台中没有任何内容

【问题讨论】:

  • 您应该检查您拥有的所有可用日志文件 - 看起来要么启动 Selenium Server 测试 2 失败,或者您在测试 1 后没有干净地关闭它。没有任何日志输出很难判断不过。
  • 日志在哪里?但它是 IE 给我一个错误...
  • 我不知道您的设置可能会在哪里存储有关测试运行的日志文件;)所以您在 IE 中遇到远程服务器没有响应的错误,这不是 Selenium 的错误?
  • 是否可以调用浏览器。启动两次而不停止它?对于您的两个测试方法,init 只发生一次,并且它们共享同一个浏览器实例
  • @Nikolay 我已经尝试在我的 testMethod 中设置停止,但它并没有改变任何事情。

标签: c# .net unit-testing selenium visual-studio-2012


【解决方案1】:

你试过这样吗?我总是在测试设置中启动 selenium。 (我也在使用 Nunit

[SetUp]
public void init()
{
    _browser = new DefaultSelenium("localhost", 4444, @"*iehta",   "http://localhost:4444");
    _browser.Start();
    _browser.Open("http://localhost/testSite.asp");
}


[TestMethod]
public  void TestLogin()
{
    bool hasText;



    _browser.Type("id=NomUtilisateur", "admin");
    _browser.Type("id=UserPassword", "password");
    _browser.Click("name=Submit");
    _browser.WaitForPageToLoad("30000");
    hasText = _browser.IsTextPresent("test");

    Assert.IsTrue(hasText, @"The search result does not contain text ""test"".");




}
[TestMethod]
public void TestRequisitionPhotocopie()
{
    _browser.Type("id=NomUtilisateur", "admin");
    _browser.Type("id=UserPassword", "password");
    _browser.Click("name=Submit");
    _browser.WaitForPageToLoad("30000");
    _browser.Click("link=lnkTest");
    _browser.WaitForPageToLoad("30000");


}
[TearDown]
public void clean()
{
    _browser.Stop();
    //_browser.Close();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 2023-04-09
    • 2015-09-09
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多