使用MBUnit和Selenium进行测试

时间:2015-06-26 07:16:03

标签: selenium mbunit

我正在尝试使用带有MB-Unit Framework的selenium构建小型测试用例。 我已经编写了测试用例,只是重定向到http://www.google.com并搜索" firefox浏览器"。

在使用Gallio tets runner运行测试用例时,test不会执行。 它最终会出现以下错误:

enter image description here

我的测试用例在这里:

using MbUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace testfirtsMBUnit
{
  [Parallelizable]
  [TestFixture]
   class grid1
    {
      private IWebDriver driver;
      private StringBuilder verificationErrors;
      private string baseURL;

    [SetUp]
    public void SetupTest()
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities = DesiredCapabilities.Firefox();
        capabilities.SetCapability(CapabilityType.BrowserName, "firefox");
        capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
        capabilities.SetCapability(CapabilityType.Version, "38.0");

        driver = new RemoteWebDriver(new Uri("http://192.168.1.10:4444/wd/hub"), capabilities);
        baseURL = "https://www.google.co.in/";
        verificationErrors = new StringBuilder();
    }

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

    [Test]
    public void GoogleTest_firefox()
    {
        driver.Navigate().GoToUrl(baseURL + "/");
        driver.FindElement(By.Name("q")).Clear();
        driver.FindElement(By.Name("q")).SendKeys("firefox Browser");
        Thread.Sleep(5000);
    }      
  }
    }

我将集线器运行为:  enter image description here

和远程机器上的节点:

enter image description here

我对硒这一切都是新手,对MB-Unit来说...... 请建议解决方案..让我知道我做错了什么

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。当我从集线器指定浏览器的版本时,节点不必具有相同版本的浏览器。 所以我只从SetupTest()中删除了那行代码。

所以我的SetupTest()是:

public void SetupTest()
{
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities = DesiredCapabilities.Firefox();
    capabilities.SetCapability(CapabilityType.BrowserName, "firefox");
    capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
  //   capabilities.SetCapability(CapabilityType.Version, "38.0");// i have removed this line from code

    driver = new RemoteWebDriver(new Uri("http://192.168.1.10:4444/wd/hub"), capabilities);
    baseURL = "https://www.google.co.in/";
    verificationErrors = new StringBuilder();
}