开发者

How to setup Selenium WebDriver working with selenium-webdriver gem

Surprisingly, I couldn't find a first step guide on how to setup Selenium WebDriver working with selenium-webdriver gem through google university. I suppose the gem needs to know where I store all those jar files to get started. How can I 开发者_Python百科configure this?


First you have to install the gem selenium-webdriver:

gem install selenium-webdriver

Then you can start your ruby program:

#You need to require the gem "selenium-driver"
require "selenium-webdriver" 

#... see webdriver ruby api docs here: http://selenium.googlecode.com/svn/trunk/docs/api/rb/_index.html
#... Most usefull classes are Driver and Element, check them out for a good start
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit

You can find more info:

about webdriver and ruby (all said above was an attempt to summarize it)

about the Ruby webdriver API

As you can see at a glance, the Webdriver API by itself has a different "style" of normal selenium-ruby programs... If you want to use webdriver and still continue to program with the Selenium-API, you should probably chech the Selenium2.0 Remote Server, as it seems that it will use Webdriver in a transparent way, while still mantaining the same known Selenium ruby Api

If I'm wrong with some part of the info, please correct me and we will all together make it clearer :)

PD: Best found info about relationship between Selenium and Webdriver was this blog post


System.setProperty("webdriver.gecko.driver", "C:\\Xerox\\geckodriver.exe"); 
        DesiredCapabilities cap=DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        driver = new FirefoxDriver(); 
        driver.get(prop.getProperty("url"));

this is how you should start your test case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜