【发布时间】: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