开发者

Get QUnit Results Using MSTest/MSUnit

I'd like to load a browser page that is a static HTML test harness for a page running QUnit tests.

I'd like to get the values from the success/failure <span>s and test with those.

How can I load a page and interrogat开发者_运维知识库e elements on it using MSTest/MSUnit?


If you don't mind starting actual browser, and you don't want to put dependency on SeleniumRC (which is required for C#), you can use WatiN. Below little example from WatiN.

[Test] 
public void SearchForWatiNOnGoogle()
{
  using (var browser = new IE("http://www.google.com"))
  {
    browser.TextField(Find.ByName("q")).TypeText("WatiN");
    browser.Button(Find.ByName("btnG")).Click();

    Assert.IsTrue(browser.ContainsText("WatiN"));
  }
}

Or if you don't want to start real browser on machine you can try Selenium, and HtmlUnit. With Selenium you start HtmlUnit, tell it to load given page, and you read what you need via xpath. For example this is example from Selenium documentation how to do something similar:

using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

class Example
{
    static void Main(string[] args)
    {

        ICapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
        IWebDriver driver = new RemoteWebDriver(desiredCapabilities);

        driver.Navigate().GoToUrl("http://google.ca/");

        IWebElement element = driver.FindElement(By.Name("q"));
        element.SendKeys("Cheese!");
        element.Submit();
        System.Console.WriteLine("Page title is: " + driver.Title);
        driver.Quit();
        System.Console.ReadLine();
    }
}  

BTW with selenium you can use real browser also.

On the other hand if this page with results is local file, you just read the file and filter data you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜