2012-03-08 72 views
4

我以前使用IWebDriver來控制IE進行測試。但支持IWebDriver和IWebElement的方法非常有限。我發現屬於Selenium命名空間的ISelenium/DefaultSelenium非常有用。如何在不安裝Selenium Server的情況下使用它們來控制IE?是否可以在不安裝Selenium Server的情況下使用ISelenium/DefaultSelenium?

這裏的DefaultSelenium的構造函數:

ISelenium sele = new DefaultSelenium(**serveraddr**, **serverport**, browser, url2test); 
sele.Start(); 
sele.Open(); 
... 

看來我之前,我創建一個ISelenium對象安裝Selenium服務器。我試圖用C#+ Selenium來構建一個.exe應用程序,它可以在不同的PC上運行,並且不可能在所有PC上安裝Selenium Server(你永遠不知道哪一個是下一個運行的該應用程序)。

有誰知道如何在不安裝服務器的情況下使用ISelenium/DefaultSelenium? thx!

+0

如果您使用WebDriver(Selenium 2),它不需要啓動Selenium Server – 2012-12-13 05:02:38

回答

2

有一些Java的解決方案,而無需使用RC服務器:

1)對於硒瀏覽器的啓動:

DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setBrowserName("safari"); 
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"), new URL("http://www.google.com/"), capabilities); 
WebDriver driver = new RemoteWebDriver(executor, capabilities); 

2)硒命令:

// You may use any WebDriver implementation. Firefox is used here as an example 
WebDriver driver = new FirefoxDriver(); 

// A "base url", used by selenium to resolve relative URLs 
String baseUrl = "http://www.google.com"; 

// Create the Selenium implementation 
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl); 

// Perform actions with selenium 
selenium.open("http://www.google.com"); 
selenium.type("name=q", "cheese"); 
selenium.click("name=btnG"); 

// Get the underlying WebDriver implementation back. This will refer to the 
// same WebDriver instance as the "driver" variable above. 
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver(); 

//Finally, close the browser. Call stop on the WebDriverBackedSelenium instance 
//instead of calling driver.quit(). Otherwise, the JVM will continue running after 
//the browser has been closed. 
selenium.stop(); 

描述在這裏:http://seleniumhq.org/docs/03_webdriver.html

谷歌在C#中類似的東西。 Theres沒有其他辦法來實現這一點。

+0

Coretek,它在我的身邊運行良好。多謝!感謝您的幫助! – 2012-03-09 02:47:59

+0

我還有一個問題。這是什麼意思? 「WebDriver driverInstance =((WebDriverBackedSelenium)selenium).getWrappedDriver();」我不明白。 – 2012-03-09 02:58:40

+0

要使用webdriver命令,請調用driverInstance – ctekk 2012-03-09 09:20:46

相關問題