浏览 3463 次
锁定老帖子 主题:webdriver 自动化测试
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-04-01
最后修改:2012-04-01
测试服务器: 下载地址: http://selenium.googlecode.com/files/selenium-server-standalone-2.20.0.jar java -jar selenium-server-standalone-2.20.0.jar Ruby: Ruby使用watir-webdriver接口。 测试代码: require "watir-webdriver" require "selenium/webdriver/remote/capabilities" browser = Watir::Browser.new :remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome browser.goto("www.tudou.com") browser.text_field(:id => 'email').set 'test' browser.text_field(:id => 'pwd').set '1234' browser.button(:class => 'lg_b').click puts browser.text.include? 'SHH' browser.li(:id, "myTudouNav").fire_event("onmouseover") browser.a(:xpath, ".//*[@id='myTudouNav']/div/ul/li[12]/a").click puts browser.text.include? 'SHH' js = <<JS $('.logo').css('border', '1px solid red'); JS browser.execute_script js browser.close 安装watir-webdriver: 1. 安装ruby 1.9.3。下载地址:http://rubyinstaller.org/downloads/ 2. 安装watir-webdriver。 > gem update --system --no-rdoc --no-ri > gem install watir-webdriver --no-rdoc --no-ri 4. 安装chromedriver,用于支持chrome。 下载地址:http://code.google.com/p/chromedriver/downloads/list PHP: PHP使用facebook的php-webdriver接口。 测试代码: require_once 'php-webdriver/__init__.php'; $wd_host = 'http://localhost:4444/wd/hub'; $web_driver = new WebDriver($wd_host); $session = $web_driver->session('chrome'); $session->open('http://www.tudou.com'); $session->element('css selector', '#email')->value(array('value' => str_split('test'))); $session->element('css selector', '#pwd')->value(array('value' => str_split('1234'))); $session->element('css selector', '.lg_b')->click(''); echo preg_match('/SSH/s', $session->source()) ? 'ok' : 'error'; $element = $session->element('id', "myTudouNav"); $session->moveto(array('element' => $element->getID())); $session->element('xpath', ".//*[@id='myTudouNav']/div/ul/li[12]/a")->click(''); $script = <<<JS $('.logo').css('border', '1px solid red'); JS; $session->execute(array( 'script' => $script, 'args' => array(), )); $session->close(); php-webdriver 下载地址:https://github.com/facebook/php-webdriver Python: 测试代码: from selenium import webdriver from selenium.webdriver.remote.command import Command from selenium.webdriver.common.desired_capabilities import DesiredCapabilities browser = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME); browser.get("http://www.tudou.com/"); browser.find_element_by_css_selector("#email").send_keys("test") browser.find_element_by_css_selector("#pwd").send_keys("1234") browser.find_element_by_css_selector("input.lg_b").click() element = browser.find_element_by_css_selector("#myTudouNav") browser.execute(Command.MOVE_TO, {'element': element.id}) browser.find_element_by_xpath(".//*[@id='myTudouNav']/div/ul/li[12]/a").click() js = "$('.logo').css('border', '1px solid red');"; browser.execute_script(js) browser.close() selenium python安装方法:easy_install –U selenium 参考文档(有些网站需要翻X): http://openqa.org/ http://seleniumhq.org/ http://watir.com https://github.com/watir/watir-webdriver http://code.google.com/p/selenium/ http://17test.info/ http://www.ibm.com/developerworks/cn/java/j-lo-rubytesting/ http://www.ibm.com/developerworks/cn/opensource/os-cn-watir/ http://www.facebook.com/notes/facebook-engineering/watir-to-webdriver-unit-test-frameworks/10150314152278920 http://itreallymatters.net/post/10991877834/facebook-watir-and-testing 淘宝automan介绍: http://qa.taobao.com/wp-content/uploads/2011/06/AutomanUserMenuZH-CN.pdf JsonWire协议: http://code.google.com/p/selenium/wiki/JsonWireProtocol#Command_Reference 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |