3

我使用Selenium創建了一個測試方法,類似於這樣:如何在不需要打開瀏覽器的情況下運行Selenium系統測試?

[TestFixture] 
public class Test_Google 
{ 
     IWebDriver driver; 

     [SetUp] 
     public void Setup() 
     { 
      driver = new InternetExplorerDriver(); 
     } 

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

    [Test] 
    public void TestSearchGoogleForTheAutomatedTester() 
     { 
      //Navigate to the site 
     driver.Navigate().GoToUrl("http://www.google.co.uk"); 
     //Find the Element and create an object so we can use it 
     IWebElement queryBox = driver.FindElement(By.Name("q")); 
     //Work with the Element that's on the page 
     queryBox.SendKeys("The Automated Tester"); 
      queryBox.SendKeys(Keys.ArrowDown); 
     queryBox.Submit(); 
     //Check that the Title is what we are expecting 
     Assert.True(driver.Title.IndexOf("The Automated Tester") > -1); 
    } 
} 

當測試運行時,它會打開一個IE瀏覽器,並進行了測試。假設有200種測試方法分佈在多個測試夾具上,這意味着IE必須多次打開和關閉(與測試夾具一樣多,因爲每個測試夾具打開1個瀏覽器)。

如何在不打開瀏覽器的情況下運行Selenium系統測試?

我的意思是,我想可能開發一個Windows服務來運行WinForms Web瀏覽器控件中的Selenium測試,在這種情況下,瀏覽器不必每次都打開,測試可以自動無縫運行。不知道如何實現這個呢?

或者還有其他更好的方法嗎?

謝謝,

回答

5

編號Selenium是用JavaScript編寫的;它旨在運行在真正的瀏覽器中,以測試與真實瀏覽器的兼容性。有很多其他工具可以用來運行模擬瀏覽器的測試;你可以看看HtmlUnitCanoo WebTest

希望這會幫助你。

1

您是否嘗試過XLT? 它並不需要打開瀏覽器 http://www.xceptance.com/products/xlt/what-is-xlt.html

+0

取決於你如何運行它。你可以使用HtmlUnitDriver,如果沒有GUI,你就沒問題,但是當只有真正的瀏覽器計數時,你必須使用假的X或VNC或類似的東西。 – ReneS

1

如果您願意,您可以在一個瀏覽器實例中運行所有測試。您只需將您的webdriver實例傳遞給每個測試。就像在所有測試用例可以訪問WebDriver的靜態類中都有一個singelton WebDriver一樣。工作正常,如果你有一個會話保持有用

1

driver = new HtmlUnitDriver(true); java.util.logging.Logger.getLogger(「com.gargoylesoftware」)。setLevel(Level.OFF);

相關問題