0
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 秒后被取消可执行。谁能帮我解决这个问题?

4

1 回答 1

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//
    }
}

我认为您缺少驱动程序的设置。

试试这个例子,希望它有帮助,

于 2018-07-16T09:16:44.860 回答