【问题标题】:Running parallel test with PNunit, can't read from config file使用 PNunit 运行并行测试,无法从配置文件中读取
【发布时间】:2014-08-30 18:47:17
【问题描述】:

我想在 Browserstack 中运行并行测试。这是我的测试项目

RTest(VS 2013 中的单元测试项目)

-UnitTest1.cs

-RTest.config

我打开 Nunit 并浏览到我的 dll bin/debug/RTest.dll 并且 Nunit 找到了我的测试用例

问题 我的 RTest.config 文件如下所示:

<TestGroup>
  <ParallelTests>
      <ParallelTest>
        <Name>Testing</Name>
        <Tests>
          <TestConf>
            <Name>TestFF-20-Win8</Name>
            <Assembly>RTest.dll</Assembly>
            <TestToRun>RTest.UnitTest1.TestCase</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
                <string>firefox</string> <!--browserName -->
                <string>20.0</string> <!-- version -->
                <string>Windows</string><!-- os -->
                <string>8</string><!-- os_version -->
            </TestParams>
          </TestConf>
          <TestConf>
            <Name>TestFF-21-win7</Name>
            <Assembly>RTest.dll</Assembly>
            <TestToRun>Test.UnitTest1.TestCase</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
              <string>firefox</string>
              <!--browserName -->
              <string>21.0</string>
              <!-- version -->
              <string>Windows</string>
              <!-- os -->
              <string>7</string>
              <!-- os_version -->
            </TestParams>
          </TestConf>
        </Tests>
      </ParallelTest>
  </ParallelTests>
</TestGroup>

我的 UnitTest1.cs 看起来像这样:

using NUnit.Framework;
using PNUnit.Framework;
using System;
using System.Web;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace RTest
{
    [TestFixture()]
    public class UnitTest1
    {
        private IWebDriver driver;
        private string[] testParams;

        [SetUp]
        public void Init()
        {
            testParams = PNUnitServices.Get().GetTestParams();
            String params1 = String.Join(",", testParams);
            Console.WriteLine(params1);
            String browser = testParams[0];
            String version = testParams[1];
            String os = testParams[2];
            String os_version = testParams[3];
            DesiredCapabilities capability = new DesiredCapabilities();
            capability.SetCapability("browserName", browser);
            capability.SetCapability(CapabilityType.Version, version);
            capability.SetCapability("os", os);
            capability.SetCapability("os_version", os_version);
            capability.SetCapability("browserstack.user", "testUser");
            capability.SetCapability("browserstack.key", "testPW");

            Console.WriteLine("Capabilities" + capability.ToString());

            driver = new RemoteWebDriver(new Uri("http://hub.browserstack.com:80/wd/hub/"), capability);
        }

        [Test]
        public void TestCase()
        {
            driver.Navigate().GoToUrl("http://www.google.com");
            StringAssert.Contains("Google", driver.Title);
            IWebElement query = driver.FindElement(By.Name("q"));
            query.SendKeys("Browserstack");
            query.Submit();
        }

        [TearDown]
        public void Cleanup()
        {
            driver.Quit();
        }
    }
}

当我运行我的测试时,我收到 mInstance 为空...... 我在这里做错了什么?

【问题讨论】:

  • 没有人可以帮我吗?
  • 您在哪里可以解决问题?

标签: visual-studio-2013 webdriver nunit browserstack pnunit


【解决方案1】:

尝试将RTest.config 重命名为test.conf

【讨论】:

    【解决方案2】:

    PNunit 很久没有维护了。我发现了一个新的开源分布式运行器,可以分布式和并行运行 NUnit 测试,您可以查看项目 documentation

    一般来说,您有测试控制器和测试代理。测试代理运行您的测试。 首先启动服务器

    meissa.exe 初始化服务器

    1. 在同一台或多台机器上启动测试代理:

    meissa.exe testAgent --testAgentTag="APIAgent" --testServerUrl="http://IPServerMachine:5000"

    1. 运行指向服务器 URL 的测试

    meissa.exe 运行器 --resultsFilePath="pathToResults\result.trx" --outputFilesLocation="pathToBuildedFiles" --agentTag="NUnit" --testTechnology="MSTestCore" --testLibraryPath="pathToBuildedFiles\SampleTestProj.dll"

    这很棒,因为您根本不需要任何配置文件或更改代码。它可以与 .NET Framework 和 .NET Core 项目一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      相关资源
      最近更新 更多