如何使用Selenium WebDriver进行跨浏览器测试

This article was originally published on LambdaTest. Thank you for supporting the partners who make SitePoint possible.

本文最初在LambdaTest发布 感谢您支持使SitePoint成为可能的合作伙伴。

Selenium is a popular automation testing framework that is primarily used for cross browser testing. It is open source and is ideal for automating testing of web applications across different browsers like Firefox, Chrome, Internet Explorer, and Microsoft Edge. Selenium has become a renowned framework and is giving stiff competition to other test frameworks such as HP QTP (Quick Test Professional) and AKA HP UFT (Unified Functional Testing). This tutorial for Selenium WebDriver will help you develop a basic understanding of the components of the Selenium suite, the Selenium WebDriver architecture and will show you how to run automation to test a website for cross browser compatibility using Selenium WebDriver for Google Chrome, Mozilla Firefox and Internet Explorer.

Selenium是一种流行的自动化测试框架,主要用于跨浏览器测试 。 它是开源的,非常适合跨Firefox,Chrome,Internet Explorer和Microsoft Edge等不同浏览器自动测试 Web应用程序。 Selenium已成为著名的框架,并且正在与其他测试框架(如HP QTP(快速测试专业版)和AKA HP UFT(统一功能测试))进行激烈竞争。 Selenium WebDriver的本教程将帮助您对Selenium套件的组件,Selenium WebDriver体系结构有基本的了解,并向您展示如何使用Selenium WebDriver for Google Chrome,Mozilla Firefox和Windows XP运行自动化以测试网站是否具有跨浏览器兼容性。 IE浏览器。

Selenium is a combination of different tools and each tool plays a critical role in automating web testing. Let’s dive into the WebDriver tutorial.

Selenium是不同工具的组合,每个工具在自动化Web测试中都扮演着至关重要的角色。 让我们深入了解WebDriver教程。

Selenium Suite的组件 (Components of the Selenium Suite)

Below are the core components of the Selenium Test Suite:

以下是Selenium测试套件的核心组件:

  • Selenium Integrated Development Environment (IDE)

    Selenium综合开发环境(IDE)
  • Selenium Remote Control (RC)

    Selenium遥控器(RC)
  • Selenium WebDriver

    Selenium WebDriver
  • Selenium Grid

    Selenium网格

Now, let’s have a look at these components in details, in this Selenium WebDriver tutorial.

现在,在此Selenium WebDriver教程中,让我们详细了解这些组件。

Selenium综合开发环境(IDE) (Selenium Integrated Development Environment (IDE))

Selenium IDE is a simple Firefox plugin and it is used to record and playback scripts. However, the Selenium IDE can only be used to write automation scripts for automating testing of simple use cases. Selenium IDE does not support conditional statements, exception handling, loops, screenshot capture, etc. For automating complex use cases, a majority of developers and testers prefer to opt for Scripting testing instead of Record & Replay testing. The Selenium test suite consists of Selenium Remote Control (RC) or Selenium WebDriver.

Selenium IDE是一个简单的Firefox插件,用于记录和回放脚本。 但是,Selenium IDE只能用于编写自动化脚本来自动化简单用例的测试。 Selenium IDE不支持条件语句,异常处理,循环,屏幕截图捕获等。为了自动执行复杂的用例,大多数开发人员和测试人员都喜欢选择脚本测试而不是“记录与重放”测试 。 Selenium测试套件由Selenium远程控制(RC)或Selenium WebDriver组成。

Selenium IDE is available for different operating systems namely Windows, Linux, Mac OS, etc. Selenium IDE for Firefox can be downloaded here.

Selenium IDE适用于Windows,Linux,Mac OS等不同的操作系统。可以在此处下载Firefox的Selenium IDE。

Selenium遥控器(RC) (Selenium Remote Control (RC))

For testing complex scenarios, Selenium Remote Control (RC) can be used. It is based on the client-server model which makes it possible to execute tests on the browser that is controlled by the server. There are client libraries in different programming languages which make it easy for developers to write effective test cases in a programming language in which they are comfortable & have expertise with. Since version 2.25.0, RC has support for Java, C#, Python, Perl, Ruby, etc.

为了测试复杂的场景,可以使用Selenium远程控制(RC)。 它基于客户端-服务器模型,该模型可以在服务器控制的浏览器上执行测试。 客户端库具有不同的编程语言,这使开发人员可以轻松以他们熟悉且具有专业知识的编程语言编写有效的测试用例 。 从2.25.0版开始,RC支持Java,C#,Python,Perl,Ruby等。

Selenium Server is the core component of the Selenium RC. Some of the core features/responsibilities of the Selenium RC are below:

Selenium Server是Selenium RC的核心组件。 Selenium RC的一些核心功能/职责如下:

  • Contains the core Selenium Framework and it is mainly responsible for injecting the same in the browser.

    包含核心的Selenium Framework,并且主要负责将其注入浏览器。
  • The client program sends commands to the RC which are then interpreted by the server and then sent to the browser.

    客户端程序将命令发送到RC,然后由服务器解释,然后发送到浏览器。
  • After execution, the results are sent back to the client.

    执行后,结果将发送回客户端。
  • The Client & Server communicate via the normal mechanism of HTTP GETS and POSTs.

    客户端和服务器通过HTTP GETS和POST的常规机制进行通信。

As mentioned earlier, the Selenium RC supports different browsers, unlike Selenium IDE which is only available for Mozilla Firefox. The downside of Selenium RC is that it does not support record & playback functionality which can be vital in the automation of test cases where tasks are repetitive, especially for regression testing. Before executing the tests using Selenium RC, an instance of the Selenium RC Server should be manually invoked and that instance should be running throughout your entire test cycle.

如前所述,与仅适用于Mozilla Firefox的Selenium IDE不同,Selenium RC支持不同的浏览器。 Selenium RC的缺点是它不支持记录和回放功能,这对于任务重复的测试用例的自动化至关重要,特别是对于回归测试而言 。 在使用Selenium RC执行测试之前,应手动调用Selenium RC Server的实例,并且该实例应在整个测试周期中都在运行。

Selenium WebDriver (Selenium WebDriver)

We know that Selenium IDE is GUI based, where Sele

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值