class NunitTest
{
IWebDriver driver;
[SetUp]
public void Initialize()
{
driver = new FirefoxDriver();
}
[Test]
public void openAppTest()
{
driver.Url ="http://www.demoqa.com";
}
[TearDown]
public void EndTest()
{
driver.Close();
}
}
我编写了一个简单的测试用例,但是当我尝试使用Visual Studio 2017运行测试时,它显示此测试发现错误消息针对可执行文件在30秒后被取消。有人可以帮我吗?
答案 0 :(得分:0)
尝试以下代码示例:
namespace Testing
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework.Constraints;
using NUnit.Framework;
using NUnit.Core.Extensions;
using System.Configuration;
using System.IO;
using System.Reflection;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium;
using Syncfusion.UnitTesting.Framework;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Support.UI;
using System.Collections;
using OpenQA.Selenium.Firefox;
using System.Diagnostics;
using System.Globalization;
using System.Drawing;
using SanityTesting.AccordionFluent;
using System.Windows.Forms;
[TestFixture("Firefox")]
public class TestClass : NUnitUtil
{
string activeBrowser;
public TestClass(string browser)
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\Drivers");
service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
System.Environment.SetEnvironmentVariable("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
driver = new FirefoxDriver(service);
activeBrowser = browser;
}
[TestFixtureTearDown]
public void quitDriver()
{
driver.Quit();
}
[Test)]
[Category("Sanity")]
public void Test1(string url, int time)
{
//your test code//
}
}
我认为您缺少驱动程序设置。
尝试这个示例,希望对您有所帮助,