2012-07-05 89 views
0

我的解決方案Web和SeleniumTests是單元測試項目中的兩個項目。如何從基於硒的單元測試項目訪問Web項目?

我的TestClass用下面的方法:

[TestMethod] 
public void Demo1() 
{ 
    // Create a new instance of the Firefox driver. 

    // Notice that the remainder of the code relies on the interface, 
    // not the implementation. 

    // Further note that other drivers (InternetExplorerDriver, 
    // ChromeDriver, etc.) will require further configuration 
    // before this example will work. See the wiki pages for the 
    // individual drivers at http://code.google.com/p/selenium/wiki 
    // for further information. 
    IWebDriver driver = new FirefoxDriver(); 

    //Notice navigation is slightly different than the Java version 
    //This is because 'get' is a keyword in C# 
    driver.Navigate().GoToUrl("http://www.google.com/"); 

    // Find the text input element by its name 
    IWebElement query = driver.FindElement(By.Name("q")); 

    // Enter something to search for 
    query.SendKeys("Cheese"); 

    // Now submit the form. WebDriver will find the form for us from the element 
    query.Submit(); 

    // Google's search is rendered dynamically with JavaScript. 
    // Wait for the page to load, timeout after 10 seconds 
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
    wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); 

    // Should see: "Cheese - Google Search" 
    System.Console.WriteLine("Page title is: " + driver.Title); 

    //Close the browser 
    driver.Quit(); 
} 

一切都很好,但在現實世界中,我不希望訪問Google.com,但Web項目的某一頁。是否有訪問它沒有明確的書面方式作爲URL中driver.Navigate().GoToUrl("http://www.google.com/");

比如我要訪問Web項目的〜/ Default.aspx的一種方式。

感謝

回答

0

當你調用GoToUrl()你必須通過一個有效的URL。 「〜/ Default.aspx」不是有效的HTTP URL。

相關問題