質問

Qunitテストを実行しているページの静的HTMLテストハーネスであるブラウザページをロードします。

成功/失敗<span>sからの値を取得し、それらを使用してテストします。

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top