在Visual Studio中运行Selenium导出测试的问题
我在Visual Studio 2013中运行测试(从Selenium IDE导出)时遇到问题 当我使用Selenium IDE时,所有测试都顺利通过 在我将它们导出为.cs文件后,VisualStudio会毫无困难地发现它们,但无法让它们在基本URL之后工作。换句话说,它会加载页面,但不会发生任何事情。一段时间后,它进入超时状态并退出浏览器 我是否需要编辑代码的某些部分以使其正常工作 我在1中添加了命令。等等,2。验证和3单击按钮/元素/收音机/链接上的,但没有帮助 我希望你能帮助我解决这个问题。问候 代码(无基本URL):在Visual Studio中运行Selenium导出测试的问题,selenium,testing,Selenium,Testing,我在Visual Studio 2013中运行测试(从Selenium IDE导出)时遇到问题 当我使用Selenium IDE时,所有测试都顺利通过 在我将它们导出为.cs文件后,VisualStudio会毫无困难地发现它们,但无法让它们在基本URL之后工作。换句话说,它会加载页面,但不会发生任何事情。一段时间后,它进入超时状态并退出浏览器 我是否需要编辑代码的某些部分以使其正常工作 我在1中添加了命令。等等,2。验证和3单击按钮/元素/收音机/链接上的,但没有帮助 我希望你能帮助我解决这个问
你们能告诉我们你们在做什么吗?我使用SeleniumIDEforFireFox记录测试并将其导出为.cs文件。在VisualStudio2013中导入后,它只加载基本URL,之后不做任何操作。如何将代码粘贴到这里?
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTests
{
[TestFixture]
public class Black
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "https://something.com/";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheBlackTest()
{
driver.Navigate().GoToUrl(baseURL + "something");
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if (IsElementPresent(By.Id("something"))) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if (IsElementPresent(By.Id("something"))) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.IsTrue(IsElementPresent(By.Id("something")));
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.CssSelector("#something > div.ng-binding")).Click();
driver.FindElement(By.CssSelector("#something > div.ng-binding")).Click();
driver.FindElement(By.Id("something")).Click();
driver.FindElement(By.Id("something")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
}
private string CloseAlertAndGetItsText()
{
try
{
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert)
{
alert.Accept();
}
else
{
alert.Dismiss();
}
return alertText;
}
finally
{
acceptNextAlert = true;
}
}
}