Вопрос

Я хотел бы загрузить страницу браузера, которая представляет собой статический жгут теста HTML для страницы, выполняющих тесты Qunit.

Я хотел бы получить ценности от успеха / провала генеракодичец и тестировать с теми.

Как я могу загрузить страницу и допрашивать элементы на нем, используя 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