怎么写第一个Selenium脚本.docx_第1页
怎么写第一个Selenium脚本.docx_第2页
怎么写第一个Selenium脚本.docx_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Selenium Webdriver开发入门1 文档目的 编写此文档的目的在于帮助更多想学习Selenium webdriver的同好们,最近发现好多人想学习Selenium做自动化,又不知道怎么入门,因此写下这篇入门的文档供各位使用,希望大家能更快的领会到Selenium webdriver 的强大之处。本文只对Selenium webdriver入门作介绍,Selenium rc由于本人认为已经过时,不做介绍。另外本文是一个初级入门文档,想要深入学习的话,并不合适。本文假定你有一定的编程水平,因此对于以下基本编程问题不在这做介绍。2 Selenium 是什么l Selenium是一组工具的集合。包括Selenium Rc,Selenium Grid,Selenium IDE,Selenium Webdriver.l 目前大家都在说的Selenium通常是指Selenium Webdriver也就是Selnium2.0.既然说到了Selenium2.0,在这也提一下什么是selenium1.0好了,1.0版本的selenium1.0主要是指Selenium RC(一个基于Javascript注入的工具),Selenium Grid,SeleniumID等工具的集合。在讲Webdriver集成到Selenium之后发布了Selenium 2.0版本。l Selenium Rc和Selenium webdriver的区别,这里简单说一下。Selenium rc对于多个浏览器窗口并不支持,所以有些情况处理不了,Webdriver能干Selenium rc能干的所有事,而且支持多浏览器窗口。当然了,Webdriver的缺点也在于支持的浏览器没有Selenium rc多。但是不代表不够用。下图是官网上Webdriver对浏览器支持的信息l Google Chrome 12.0.712.0+l Internet Explorer 6, 7, 8, 9 - 32 and 64-bit where applicablel Firefox 3.0, 3.5, 3.6, 4.0, 5.0, 6, 7l Opera 11.5+l HtmlUnit 2.9l Android 2.3+ for phones and tablets (devices & emulators)l iOS 3+ for phones (devices & emulators) and 3.2+ for tablets (devices & emulators)l 注意以上对于移动设备的支持是说对移动设备上的浏览器的支持,支持的浏览器版本是特定的。3 怎样开始开发自己的第一个Webdriver脚本。 本文以C#语言作为示例开发语言,开发工具选用VS2010。题外话,语言只是工具使用什么语言开发脚本都无所谓。在阅读本小节的前提是假定你已经会创建C# 控制台或者测试项目。1) 前期准备l 在官网的下载页面找到C#版本的weddriver下载下来(Selenium Client & WebDriver Language Bindings)l 对于IE浏览器你还需要下载The Internet Explorer Driver Serverl 下载上述包文件后,解压缩。2) 创建C# 控制台项目并添加对Webdriver.dll的引用。开始编写第一个脚本吧。下面是官网给出的示例。3) using OpenQA.Selenium;4) using OpenQA.Selenium.Firefox;5)6) / Requires reference to WebDriver.Support.dll7) using OpenQA.Selenium.Support.UI;8)9) class GoogleSuggest10) 11) static void Main(string args)12) 13) / Create a new instance of the Firefox driver.14)15) / Notice that the remainder of the code relies on the interface, 16) / not the implementation.17)18) / Further note that other drivers (InternetExplorerDriver,19) / ChromeDriver, etc.) will require further configuration 20) / before this example will work. See the wiki pages for the21) / individual drivers at /p/selenium/wiki22) / for further information.23) IWebDriver driver = new FirefoxDriver();24)25) /Notice navigation is slightly different than the Java version26) /This is because get is a keyword in C#27) driver.Navigate().GoToUrl(/);28)29) / Find the text input element by its name30) IWebElement query = driver.FindElement(By.Name(q);31)32) / Enter something to search for33) query.SendKeys(Cheese);34)35) / Now submit the form. WebDriver will find the form for us from the element36) query.Submit();37)38) / Googles search is rendered dynamically with JavaScript.39) / Wait for the page to load, timeout after 10 seconds40) WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10);41) wait.Until(d) = return d.Title.ToLower().StartsWith(cheese); );42)43)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论