http://www.softwaretestinghelp.com/selenium-webdriver-selenium-tutorial-8/
Introduction to Selenium WebDriver:
Earlier in this series we published tutorials which focused more onSelenium IDE and its various aspects. We introduced the tool and discussed about its features. We also constructed a few scripts using Selenium IDE and Firebug. From there we moved on to different types of web elements available and their locating strategies.
Now that we are well versed with Selenium IDE, let us move our learning curve towards creating more advanced automation scripts using Selenium WebDriver. WebDriver is one of the most compelling automation testing tools. Let us discuss it in detail.
Introduction
WebDriver is one of the most powerful and popular tools of Selenium toolkit. WebDriver comes as an extended version to Selenium RC with superfluous advantages and addresses many of its limitations. WebDriver extends its support to many latest browsers and platforms unlike Selenium IDE. WebDriver also doesn’t require Selenium server to be started prior to execution of the test scripts unlike Selenium RC.
Selenium RC in aggregation with WebDriver API is known as Selenium 2.0. Selenium was so developed in order to support dynamic web pages and Ajax calls. It also supports various drivers to exercise web based mobile testing.
Architecture
WebDriver is a web-based testing tool with a subtle difference with Selenium RC. Since, the tool was built on the fundamental where an isolated client was created for each of the web browser; no JavaScript Heavy lifting was required as we discussed in our very first tutorial.
WebDriver makes direct calls to the Web browser and the entire test script is executed in this fashion. WebDriver uses the browsers support and capabilities to automation.
Unlike Selenium RC, Selenium WebDriver doesn’t essentially require Selenium Server to be started before launching the test script execution. User can leverage the benefit and may or may not require Selenium Server if he/she desires to perform the test execution on the same machine where the browser is residing.
Exceptional Cases when Selenium Server is required with WebDriver:
- When the user wish to execute test scripts on the remote machine.
- When the user wish to execute test scripts on HtmlUnit Driver.
- When the user wish to execute test scripts on multiple platforms.
WebDriver is a purely object oriented framework that works on OS layer. It utilizes the browser’s native compatibility to automation without using any peripheral entity. With the increasing demand it has gained a large popularity, user base and has become by far one of the most extensively used open source automation testing tool.
Features of Selenium WebDriver
Browser Compatibility
WebDriver supports diverse range of web browsers and their versions. It supports all the conventional browsers in addition to some unique and rare browsers like HtmlUnit browser unlike Selenium RC and Selenium IDE.
HtmlUnit Browser executes the test scripts analogous to other browsers except the fact that it runs in the headless mode i.e. GUI-less mode and the user won’t be able to view the test script execution. Said that the test script execution transpires in headless mode, thus the execution speed takes a roll and quickens the execution.
WebDriver also supports web based mobile testing. Thus it provides AndroidDriver and IphoneDriver to back web based mobile testing.
Note: WebDriver doesn’t readily support new browsers.
Language Support
Earlier in the sessions we learned to create scripts using record and playback functionality. We also saw how to create them manually using Selenese commands. While creating such test scripts, we come across various constraints.
Some of the limitations imposed by Selenium IDE are:
- Doesn’t support iterations and conditional statements
- Doesn’t support loops
- Doesn’t support error handling
- Doesn’t support test script dependency
The above impediments can be troubleshot programmatically. WebDriver facilitates the user to choose within the different programming languages and build their test script in the designated language.
Selenium WebDriver supported programming languages are:
- Java
- C#
- PHP
- Pearl
- Ruby
- Python
Thus the user can pick any one of the programming language (provided the language is supported by WebDriver) based on his/her competency and can start building test scripts.
Speed
When compared to other tools of Selenium suite, WebDriver turns out to be the fastest tool amongst all. The communication is not channelized via any external intervention; rather the tool directly communicates with the browser same as that of any user. Thus, WebDriver takes advantage of the browser’s native compatibility towards automation.
------------
Other tools from Selenium suite like Selenium RC don’t communicate directly with the web browser. Client libraries (test scripts written in any programming language) communicate with Selenium Remote Control Server and Remote Control communicates with a Selenium Core (JavaScript Program) which in turn communicates with the web browser. Hence, this sort of twisted communication results as a hindrance on execution speed.
Drivers, Methods and Classes
WebDriver offers a wide range of solutions to some potential challenges in Automation Testing. It helps us to deal with complex types of web elements like checkboxes, dropdowns, and alerts with the help of dynamic finders.
With the advent of mobile era, WebDriver API has also matured and introduced some of the key technologies to enter this horizon. WebDriver enables user to perform web based mobile testing. It provides two of the essentials drivers to perform web based mobile testing.
- AndriodDriver
- IphoneDriver
Moreover, WebDriver API is fairly simple and easy. It doesn’t include repetitious commands. On the contrary, Selenium RC embodies many of the tautological commands.
Conclusion
In this tutorial, we tried to make you acquainted with Selenium WebDriver by outlining its architecture, features and limitations.
Here are the cruxes of this article.
- Selenium suite is comprised of 4 basic components; Selenium IDE, Selenium RC, WebDriver, Selenium Grid.
- WebDriver allows user to perform web based automation testing. WebDriver is a different tool altogether that has various advantages over Selenium RC.
- WebDriver supports a wide range of web browsers, programming languages and test environments.
- WebDriver directly communicates with the web browser and uses its native compatibility to automate.
- WebDriver’s support doesn’t only limits in the periphery of traditional user actions. Instead it supports efficient handling mechanisms for complex user actions like dealing with dropdowns, Ajax calls, switching between windows, navigation, handling alerts etc.
- WebDriver enables user to perform web based mobile testing. To support the same, WebDriver introduces AndroidDriver and IphoneDriver.
- WebDriver is faster than other tools of Selenium Suite because it makes direct calls to browser without any external intervention.
Next Tutorial #9: In the next tutorial, we would be discussing about the installation procedure to get started with WebDriverinitiating from the scratch. We would also be discussing about thediverse range of drivers provided by WebDriver, each catering to different needs.
Till the time our next tutorial is under construction, the readers can visit the Selenium’s official website. A detailed documentation with reference to Selenium WebDriver is implemented at its official website.
About the author: Shruti Shrivastava is currently working as a Senior Test Engineer with 4+ years of automation testing experience. She is an ISTQB certified professional and also an active blogger, always interested in solving testing related problems.
We also have two more authors on this Selenium tutorial’s series to make it complete, useful and relevant.
相关推荐
Chrome Webdriver位于您的计算机上,并且位于PATH中。 以下是互联网上的一些资源可以为您提供帮助。 运行独立的服务器jar文件-它看起来应如下所示: java -jar selenium-server-standalone-3.141.59.jar (用您的...
System.setProperty("webdriver.chrome.driver", "path/to/your/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.google.com"); WebElement searchBox = driver.find...
TestNG和Selenium Webdriver文章链接的示例项目:://www.swtestacademy.com/selenium-tutorial-java-testng/" 描述中提到的链接提供了一个详细的教程,指导用户了解如何使用TestNG与Selenium WebDriver进行Web自动...
本教程“selenium-tutorial”旨在引导用户了解如何利用Java有效地编写Selenium WebDriver测试。 首先,我们要了解Selenium WebDriver。WebDriver是Selenium的最新接口,它允许与各种浏览器进行直接通信,实现跨...
file 下载文件存放路径,通过chromeOptions capability设置 -unittest_demo unittest selenium 示例代码 -allure-2.17.2 allure报告 -save_images webdriver 截图保存图片路径 -webdriver_init.py webdriver 初始化...
search_box.send_keys("Selenium Tutorial") search_box.submit() ``` ### 5. 断言与等待 在编写测试脚本时,我们通常会使用断言来验证预期结果。Python的unittest或pytest库中的assert语句可以用于此目的。此外,...
2. **WebDriver**:Selenium的核心组件是WebDriver,它允许你控制和自动化浏览器的行为。WebDriver接口提供了许多方法,如打开网页、点击元素、填写表单等。 3. **WebElement**:WebDriver与页面上的HTML元素进行...
1. **Selenium WebDriver**:作为Selenium的主要接口,WebDriver允许与多种浏览器进行通信,模拟用户操作。 2. **元素定位**:学习XPath、CSS选择器、ID、Name等方法,找到页面上的特定元素。 3. **交互操作**:...
searchBox.sendKeys("Selenium Tutorial"); searchBox.submit(); ``` 最后,别忘了在测试结束后关闭浏览器: ```java driver.quit(); ``` **四、定位元素** Selenium提供了多种方式来定位页面上的元素,如`By.id...
Chimp是基于JavaScript的端到端测试框架,它集成了Cucumber.js、Selenium WebDriver、Mocha和Chai等库,使得开发者能够用简单的语法编写可读性强的测试脚本。 ## Chimp简介 Chimp提供了一种简洁的方式来执行Web应用...
search_box.send_keys('Selenium Python Tutorial') # 提交搜索 search_box.submit() # 关闭浏览器 driver.quit() ``` 这个过程可能会遇到一些常见问题,比如驱动版本不匹配、浏览器版本过旧等,需要根据实际情况...
3. 集成测试:与Selenium WebDriver等工具配合,可以进行GUI层面的集成测试。 五、进阶特性 1. 参数化测试:@Parameterized测试允许用不同的参数多次运行同一个测试方法,提高测试覆盖率。 2. 立即失败:使用...
安装依赖项(仅表达): $ npm install 您需要在单独的终端标签/窗口中执行以下操作- 首先启动Selenium服务器: $ webdriver-manager start 启动应用程序: $ node server.js 最后,开始量产! $ protractor conf2....
Working with PHPUnit and Selenium Webdriver PHPUnit文档 The Clean Architecture in PHP 读书笔记 基于MySQL和PHP的分布式事务处理 PHP7内核剖析 Concise Guide to Swoole Laravel API Tutorial: How to Build ...
此外,selenium-webdriver提供了与不同浏览器的兼容性,使得自动化测试更具灵活性。 最后,不要忘记Jupyter Notebook,这是一个交互式计算环境,允许您混合编写代码、文本和图像,非常适合数据探索和教学。通过...
- 通过命令行安装Watir和其驱动程序(以Selenium WebDriver为例,因为它支持多种浏览器): ```bash gem install watir-webdriver ``` 2. **编写第一个Watir脚本**: - 创建一个新的Ruby文件(例如`example_...