我有以下硒测试:
open /dealerproducts.preprod/MainPage.aspx
type id=ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtLoginEmail_I tester@gmail.com
type id=ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtPwd_I pass123
clickAndWait css=#ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_btnLogin_CD > span
click link=Search Contract
selectFrame id=ContentPlaceHolder1_tabPages_frContent1
pause 1000
click id=grdList_header2_colFilter_2_txtValue1_2
type id=grdList_header2_colFilter_2_txtValue1_2 PM10000130
click css=span
click id=grdList_cell0_2_lnkNumber_0
当我在 Selenium IDE 中运行此测试时,始终单击最后一个链接 (id=grdList_cell0_2_lnkNumber_0)。但是,当 nunit.exe 运行以下测试(即导出到 c# 的上述测试)时,不会单击最后一个链接:
[TestFixture]
public class ElanceTestWebDriver
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "http://mysite.com/";
verificationErrors = new StringBuilder();
}
[Test]
public void TheElanceTestWebDriverTest()
{
driver.Navigate().GoToUrl(baseURL + "/dealerproducts.preprod/MainPage.aspx");
driver.FindElement(By.Id("ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtLoginEmail_I")).Clear();
driver.FindElement(By.Id("ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtLoginEmail_I")).SendKeys("tester@gmail.com");
driver.FindElement(By.Id("ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtPwd_I")).Clear();
driver.FindElement(By.Id("ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_txtPwd_I")).SendKeys("pass123");
driver.FindElement(By.Id("ucTopBar_ASPxRoundPanel2_ucLogin_cbLogin_pnl_btnLogin_CD")).Click();
driver.FindElement(By.LinkText("Search Contract"), 2).Click();
driver.SwitchTo().Frame("ContentPlaceHolder1_tabPages_frContent1");
driver.FindElement(By.Id("grdList_header2_colFilter_2_txtValue1_2")).Click();
driver.FindElement(By.Id("grdList_header2_colFilter_2_txtValue1_2")).Clear();
driver.FindElement(By.Id("grdList_header2_colFilter_2_txtValue1_2")).SendKeys("PM10000130");
driver.FindElement(By.CssSelector("span")).Click();
IWebElement el = null;
el = driver.FindElement(By.Id("grdList_cell0_2_lnkNumber_0")); //.Click();
Assert.That(el != null); // 1.
driver.FindElement(By.Id("grdList_cell0_2_lnkNumber_0")).Click();
}
运行上述测试时始终会找到元素 id=grdList_cell0_2_lnkNumber_0,因为断言 1. 永远不会失败。奇怪的是,当这个测试在 Visual Studio 的调试模式下逐步运行时,总是点击链接。链接的 HTML:
<a class="dxeHyperlink" onclick="aspxSEClick('grdList_cell0_2_lnkNumber_0', event)" id="grdList_cell0_2_lnkNumber_0" style="font-size:9px;">PM10000130</a>
谁能告诉我为什么在 nunit.exe 或 nunit-x86.exe 运行测试时没有点击这个链接?