博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Selenium 不同版本的区别
阅读量:4040 次
发布时间:2019-05-24

本文共 22054 字,大约阅读时间需要 73 分钟。

Selenium 是用于测试 Web 应用程序用户界面 (UI) 的常用框架。它是一款用于运行端到端功能测试的超强工具。您可以使用多个编程语言编写测试,并且 Selenium 能够在一个或多个浏览器中执行这些测试。

用“一个工具”这样的字眼来形容Selenium并不恰当。Selenium是一套WEB应用的测试框架,为了满足不同的需要,它提供了几个组件形成了所谓的“Selenium”家族。其家族成员后面的文章中有介绍。

起源

Jason Huggins,当时在ThoughtWorks工作,2004年发起了Selenium项目。Jason和他所在的团队采用Javascript编写一种测试工具来验证浏览器页面的行为;这个JavaScript类库就是Selenium core,同时也是seleniumRC、Selenium IDE的核心组件。Selenium由此诞生。

后来,在 Paul Hammant 加入团队后并指导开发第二种操作模式(后来成为“Selenium Remote Control”(RC))。

2007年,Jason Huggins加入Google。与其他人一样,Jennifer Bevan,他继续发展和稳定Selenium RC的功能。与此同时,ThoughtWorks的Simon Stewart开发了一个名为WebDriver的高级浏览器自动化工具。Simon希望能通过浏览器、操作系统的底层方法等一些手段来直接操作浏览器;这样就避免了在Java Script的沙箱环境里存在的那些限制了,Web Driver项目就此诞生!2009年,在Google测试自动化会议上,开发人员举行了一次会议,会议决定合并这两个项目,并称之为新项目Selenium Web Driver,即Selenium2.0。

2008年,Philippe Hanrigou(当时在ThoughtWorks)制作了“Selenium Grid”,它提供了一个中心,允许在任意数量的本地或远程系统上同时运行多个Selenium测试,从而最大限度地减少了测试执行时间。

Selenium 1 和 WebDriver 合并成一款性能更佳的产品 Selenium 2(或 Selenium WebDriver),该款产品发行于 2011 年。

Selenium 2 具有来自 WebDriver 的清晰面向对象 API,并能以最佳的方式与浏览器进行交互。Selenium 2 不使用 JavaScript 沙盒,它支持多种浏览器和多语言绑定。

 

Selenium 1.x

用下面的图来说明 Selenium 1.x 各部分的功能

Selenium由几个组件组成,每个组件在帮助开发web应用程序测试自动化方面都扮演着特定的角色。

Selenium IDE 是嵌入到Firefox 浏览器中的一个插件,实现简单的浏览器操作的录制与回放功能。
那么什么情况下用到它呢?
快速的创建 bug 重现脚本,在测试人员的测试过程中,发现了bug 之后可以通过 IDE 将重现的步骤录制下来,以帮助开发人员更容易的重现bug。
IDE 录制的脚本可以可以转换成多种语言,从而帮助我们快速的开发脚本。
Selenium Grid

支持分布式测试,即可以在不同平台、不同浏览器的多台远程机器上同时运行Selenium测试脚本,从而提高测试效率,减少执行时间。

是一种自动化的测试辅助工具,Grid 通过利用现有的计算机基础设施,能加快WebApp的功能测试。利用Grid,可以很方便地同时在多台机器上和异构环境中并行运行多个测试事例。其特点为:

  • 并行执行
  • 通过一个主机统一控制用例在不同环境、不同浏览器下运行。
  • 灵活添加变动测试机

Selenium RC

(Remote Control) 

Selenium RC是一个用JAVA语言编写的服务端,可以处理测试脚本发送过来的HTTP请求,来操作浏览器。

是selenium 家族的核心工具,Selenium RC 支持多种不同的语言编写自动化测试脚本,通过selenium RC 的服务器作为代理服务器去访问应用从而达到测试的目的。

selenium RC 使用分Client Libraries 和Selenium Server。

  • Client Libraries 库主要主要用于编写测试脚本,用来控制selenium Server 的库。
  • Selenium Server 负责控制浏览器行为,总的来说,Selenium Server 主要包括3 个部分:Launcher、Http Proxy、Core。
Selenium Core 是被Selenium Server 嵌入到浏览器页面中的。Selenium Core就是一堆JavaScript函数的集合,就是通过这些JavaScript函数,我们才可以实现用程序对浏览器进行操作。
Launcher 用于启动浏览器,把Selenium Core 加载到浏览器页面当中,并把浏览器的代理设置为Selenium Server 的Http Proxy。

 

Selenium2.x

Selenium 2.x中包括了WebDriver。其实在Selenium2.0中主推的就是WebDriver这个模块。事实上WebDriver是Selenium RC的替代品,因为Selenium需要保留向下兼容性的原因,Selenium RC才没有被彻底的抛弃,如果使用Selenium开发一个新的自动化测试项目,那么我们强烈推荐使用Selenium2.0的WebDriver进行编码。

Selenium2.0 = Selenium1.0 + WebDriver

Selenium RC 的实质是在浏览器中运行一个JavaScript应用程序,使用每个浏览器内置的JavaScript解释器来解释和执行Selenium的命令集合。

Selenium WebDriver  与上述的Selenium RC是不同的。WebDriver针对不同的浏览器进行开发,取代了RC那样嵌入到被测试的WebApp程序中的JavaScript,使用了与浏览器更加集成的方式进行测试,避免了RC使用JavaScript而可能遇到的安全模型限制导致的问题等。

WebDriver是测试脚本的的核心。在测试脚本中,通过调用WebDriver对象的方法来操作浏览器。

简而言之,Selenium IDE是为了方便录制,Selenium Grid是为了提升执行效率,Selenium RC/WebDriver是脚本编写的核心。

Selenium RC的工作原理是,在测试脚本执行之前,需要启动Selenium服务端,通过注入JavaScript形成沙箱环境,在沙箱环境中完成测试脚本中指定的浏览器操作。

WebDriver是从浏览器外部来控制的,通过调用浏览器原生接口来驱动,完成页面操作。比如说,当我们的脚本操作Firefox浏览器的时候,WebDriver是用JavaScripts来调用API的,而当我们操作IE浏览器的时候,WebDriver就用C++了。

由于有一些页面元素在沙箱和浏览器上的展示有很大出入,因此调用浏览器原生接口或许是控制浏览器的最好方式了。但问题是,如果有新的浏览器问世,WebDriver API就无法支持,而Selenium RC可以。

Selenium RC与WebDriver合并之后,也就是Selenium2.0之后,对于主流的浏览器Chrome、IE、Firefox上的页面操作,可以基于各自的Driver文件,而无须启动服务端。同时,还支持RemoteWebDriver,使用方式与Remote Control一致。

 

Selenium 3.x

2016年10月 Selenium 3.x 发布了。

 

Selenium 4.x

 

现在,可以在Selenium官网下载最新的版本:

Selenium对多浏览器的支持:Chrome、IE、Firefox、Safari、Opera、Edge

 

 

Selenium 3 和 Selenium 4的异同

Selenium 3 Selenium 4

The Browser interaction is based on JSON wire protocol due to which it needs encoding and decoding of the API

浏览器交互基于JSON-wire协议,因此需要对API进行编码和解码

It follows the W3C standard Protocol due to which driver and the browser communication follows the standard procedure, does not require encoding and decoding of the API, so communication happens directly.

它遵循W3C标准协议,驱动程序和浏览器之间的通信遵循标准程序,不需要对API进行编码和解码,因此直接进行通信。

与体系结构相关的重要更改(Important Architecture Related Changes)

#1) Supports removed for some browsers: Now, they have removed the supports for the browsers Opera and Phantom JS. Opera users can use the Chrome browser, whereas Phantom JS users can use Chrome or Firefox in headless mode.

现在,已经删除了对浏览器Opera和Phantom JS的支持。Opera用户可以使用Chrome浏览器,而Phantom JS用户可以使用Chrome或Firefox。

#2) Optimized Selenium Grid: Selenium Grid was developed long back in 2011.

Selenium 4 has come up with new architecture to remove the issues which occurred earlier during installation and configuration, also during the connection between the hub and node machine.

Selenium4提出了新的体系结构,以消除先前在安装和配置期间,以及在Hub和Node机器之间的连接期间出现的问题。

Let’s understand in brief about the Selenium Grid, which contains two major components:

  • Node: It is used to execute tests on individual computer systems. There can be multiple nodes in a grid. 

                   它用于在单个计算机系统上执行测试。网格(Grid)中可以有多个节点。

  • Hub: It is the central point from where it controls all the machines present in the network, and it contains only one hub which helps in allocating test execution to different nodes.

                 它是控制网络中所有机器的中心点,它只包含一个集线器(Hub),可以帮助将测试执行分配给不同的节点。

But in Selenium 4, Grid is very flexible. It allows us to test the cases against multiple browsers, browsers of different versions, and also on different Operating systems. Even now, there is no need for a setup to start hub and nodes individually once the user starts the server, the Grid automatically works as both nodes and hub.

但在Selenium4中,Grid 非常灵活。它允许我们在多个浏览器、不同版本的浏览器以及不同的操作系统上测试。即使现在,一旦用户启动服务器也不需要设置单独启动Hub和Node,Grid将自动作为Node和Hub工作。

It also supports advanced tools like Docker, AWS, Azure, and much more, useful in the DevOps process. Now Grid has a more user-friendly UI and contains relevant information related to the session, running, capacity, etc.

它还支持Docker、AWS、Azure等在DevOps过程中非常有用的高级工具。现在Grid有了更友好的用户界面,包含了与会话、运行、容量等相关的信息。

#3) Standardized Documentation: Documents play an essential role for any user, and Selenium documents were not updated since Selenium 2.0.

文档对任何用户都起着至关重要的作用,自Selenium 2.0以来,Selenium文档就没有更新过。

With Selenium 4, they have updated all the official documents related to Selenium that include web driver, Grid, and IDE to explain the latest changes.

Selenium4,已经更新了所有与Selenium相关的官方文档,包括web驱动程序、Grid和IDE,以解释了最新的更改。

#4) Improvement in Selenium 4 IDE: Selenium IDE is a record and playback tool that is used for user interaction with the browser, and the new version of IDE is available with more features

Selenium IDE是一个记录和回放工具,用于用户与浏览器的交互,新版本的IDE提供了更多的功能

These features include:

  • It improves the browser support. Now with a new version, any browser vendor can easily plug into the latest Selenium IDE.

        它改进了浏览器支持。现在有了新版本,任何浏览器供应商都可以轻松地插入最新的seleniumide。

  • CLI Runner will be based on NodeJS, not the HTML-based runner, and it supports the parallel execution from which it provides the report with the total number of test cases passed/failed along with execution time taken.

        CLI Runner将基于NodeJS,而不是基于HTML的Runner,它支持并行执行,并从中提供报告,其中包含通过/失败的测试用例总数以及所用的执行时间。

#5) Better Monitoring: Logging and request tracing process are now improved to make a better grip on the debugging process for automation engineers as it is not limited to DevOps only.

日志记录和请求跟踪过程现在得到了改进,以更好地控制自动化工程师的调试过程,因为它不仅限于DevOps。

Selenium 4.0 的一些新特性

#1) 捕获特定web元素的屏幕截图(Capture screenshot of specific web element)

Earlier, users can take a screenshot of the entire page as there was no provision to take the screenshot of the specific web element. But with Selenium 4, users can take the screenshot of a specific web element.

此前,用户可以截取整个页面的截图,因为没有规定截取特定web元素的截图。但是使用selenium4,用户可以截取特定web元素的屏幕截图。

Please find the below code:

WebElement logo=driver.Findelement (By.xpath(“//div[@id=’divLogo’]//img”));

File file=logo.getScreenshotAs(OutputType.FILE);

File destFile =new File(“logo.png”);

FileUtils.copyFile(file,destfile);

#2) 打开浏览器上的新选项卡(Open the new tab on the browser)

Now, in Selenium 4, the user can open a URL in a new tab along with the existing tab.

现在,在Selenium4中,用户可以在新选项卡中打开URL以及现有选项卡。

For Example: If the user wants to open 2 URLs in two different tabs at the same time, the user can do that with the Selenium 4.

例如:如果用户希望同时在两个不同的选项卡中打开2个URL,那么用户可以使用Selenium4来完成这一操作。

Please find the below code for reference:

driver.get(https://www.google.com/);

driver.switchTo().newWindow(WindowType.TAB);

driver.navigate().to(https://www.crmpro.com/);

#3) 在浏览器上打开一个新窗口(Open a new window on the browser)

Using Selenium 4, the users can also open the new window on the same browser.

使用Selenium4,用户还可以在同一浏览器上打开新窗口。

For Example, if the user wants to access two applications in the same browser, the user can now do this.

例如,如果用户希望在同一浏览器中访问两个应用程序,那么用户现在可以这样做。

Please find the below code for reference:

driver.get(https://www.google.com/);

driver.switchTo().newWindow(WindowType.WINDOW);

driver.navigate().to(https://www.crmpro.com/);

#4) 对象位置(Object Location)

Now with Selenium 4, users can achieve the coordinates, dimension, height, width, etc. as the location of the web elements or object.

现在使用selenium4,用户可以实现坐标、尺寸、高度、宽度等作为web元素或对象的位置。

Please find the below code for your reference:

WebElement logo1=driver.Findelement(By.xpath(“//div[@id=’divLogo’]//img”));

System.out.println(“Height:” +logo.getRect().getDimension().getHeight());

System.out.println(“Height:” +logo.getRect().getDimension().getWidth());

System.out.println(“X Location: “ +Logo.getRect().getX());

System.out.println(“Y Location: “ +Logo.getRect().getY());

#5) 相对定位器(Relative Locators)

These are also known as Friendly Locators, and this functionality is being added to find out the element which is present nearby to other web element or, we can say that it can find the web elements based on GUI location.

这些也被称为友好的定位器(Locators),并且这个功能被添加来找出存在于其他web元素附近的元素,或者,我们可以说它可以基于GUI位置来找到web元素。

There are five locators added in Selenium 4:

  • below(): Web element located below for the specified element.
  • toLeftOf() : Target web element which is present to the left of specified element.
  • toRightOf(): Target web element which is presented to the right of a specified element.
  • above(): Web element located above for the specified element.
  • near() : Target web element which is away(approx. 50 pixels) from the specified element.

Note: All the above relative locators method support “withTagName” method.

The below example is for the toLeftof() and below() locators:

WebElement book;

book = driver.Findelement(RelativeLocators.withTagName(“li”).toLeftOf(By.id(“pid1”))

.below(By.id(“pid2”)));

String id1=book.getAttribute (“id1”);

The below example is for the toRightOf() and above() locators:

WebElement book1;

book1 = driver.Findelement(RelativeLocators.withTagName(“li”).toRightOf(By.id(“pid1”))

.above(By.id(“pid2”)));

String id2=book1.getAttribute (“id2”);

#6) Chrome开发工具(Chrome Dev tools)

In the new version of Selenium, they have made some internal changes in the API. Earlier in Selenium 3, the Chrome driver extends directly to the Remote Web Driver class. But now in Selenium 4, Chrome driver class extends to Chromium Driver. Chromium Driver class has some predefined methods to access the dev tool.

在Selenium的新版本中,对API进行了一些内部更改。在Selenium 3之前,Chrome driver 直接扩展到 Remote Web Driver类。但现在在Selenium4中,Chrome driver类扩展到了 Chromium Driver。Chromium Driver类有一些预定义的方法来访问开发工具。

Note: Chromium Driver extends the Remote Web driver class.

 


Selenium是一种广泛用于web应用程序自动化测试的工具。90%的公司将Selenium用于UI自动化。这是一个流行的选择,因为Selenium可以用许多编程语言编写,包括Java、JavaScript、C#和Python。

Selenium 常见面试题目

1. Selenium是什么?(What is Selenium?)

Selenium is a tool for automating everything you can do inside a web browser. It automates functional aspects of web-based applications and can run across all browsers and platforms.

Selenium是一个工具,它可以使您在web浏览器中所能做的一切自动化。它自动化了基于web的应用程序的功能,并且可以在所有浏览器和平台上运行。

Selenium是一个用于测试web应用程序的可移植框架。Selenium提供了一个用于编写功能测试的回放工具,无需学习测试脚本语言(seleniumide)。它还提供了一种特定于测试域的语言(Selenese),可以用许多流行的编程语言编写测试,包括C#、Groovy、Java、Perl、PHP、Python、Ruby和Scala。这些测试可以在大多数现代网络浏览器上运行。Selenium运行在Windows、Linux和macOS上。它是根据Apache许可证2.0发布的开源软件。

2. Selenium suite包含哪些组件?(Which are the components of the Selenium suite)

Selenium is not just a single tool or a utility. Rather, it’s a bundle of multiple test tools, referred to as a suite. Each of the tools is designed to meet specific criteria for testing and testing environments.

Selenium 不仅仅是一种工具或实用工具。相反,它是多个测试工具的集合(捆绑包),称为一个套件(Suite)。每种工具都是为了满足测试和测试环境的特定标准而设计的。

它包含下面的一些组成部分:

  • Selenium IDE (Integrated Development Environment) – Open-source record and playback test automation for the web. This is distributed as a plug-in to Firefox and Chrome.
  • Selenium RC (Remote Control) – Selenium RC is a server that allows a user to build test scripts in a desired programming language. It also enables test scripts to be performed across a wide spectrum of browsers.
  • Selenium WebDriver – WebDriver is an entirely different tool, with different advantages over Selenium RC. WebDriver interacts directly with the web browser and makes use of its native compatibility to automate. 
  • Selenium Grid – Selenium Grid is used to simultaneously distribute the test execution on multiple platforms and environments.

3. Selenium在自动化测试的框架中有哪些优势?(What are the advantages of Selenium in the automation testing world?)

Selenium is a free open-source platform and supports a wide array of users and support communities. It’s compatible across systems, making it friendly for Windows, Linux, and Mac users. It supports Java, Python, Perl, PHP, C#, and Ruby programming languages.Since Selenium is compatible with cross-browser testing, it works on almost all common browsers including Chrome, Firefox, Edge, Internet Explorer and Safari. Another benefit is that Selenium Grid allows for parallel execution. 

Selenium是一个免费的开源平台,支持广泛的用户和支持社区。它跨系统兼容,对Windows、Linux和Mac用户都很友好。它支持Java、Python、Perl、PHP、C#和Ruby编程语言。

由于Selenium与跨浏览器测试兼容,它几乎可以在所有常见浏览器上工作,包括Chrome、Firefox、Edge、ID和Safari。另一个好处是Selenium Grid允许并行执行。

4. WebDriver是什么?(What is WebDriver?)

WebDriver is a simple and concise programming interface. As an object-oriented and lightweight API, it drives the browser through interface-type reference variables.

WebDriver是一个简单而简洁的编程接口。作为一个面向对象的轻量级API,它通过接口类型引用变量驱动浏览器。

5. 什么是Selenium 4?(What is Selenium 4?)

Selenium 4 is the latest version of Selenium WebDriver, which will be fully standardized with W3C. Since most browsers such as Chrome, Safari, Firefox, Internet Explorer, and Edge follow W3C standardization, browser drivers will interact with Selenium WebDriver in W3C standard protocol.

Selenium 4是Selenium WebDriver的最新版本,它将完全遵守W3C标准化。由于大多数浏览器(如Chrome、Safari、Firefox、Internet Explorer和Edge)都遵循W3C标准化,浏览器驱动程序将以W3C标准协议与Selenium WebDriver交互。

6. Selenium4有哪些值得注意的特性?(What are some noteworthy Selenium 4 features?)

  • Selenium Grid – The hubs and nodes are smooth to set up and handle now. Once a Selenium server is started, the grid will act both as a hub and node.
  • Taking screenshots at the Element level, Section level and Page level is possible now.
  • Support for the Chromium driver for Microsoft Edge browser
  • Support of Relative Locators
  • In one browser window, running with different browsers at the same time and with different tabs

7. Selenium 4中的所有相对定位器是什么?(What are all the relative locators in Selenium 4?)

We have several methods of finding a (relative) element close by. These are:

我们有几种方法可以找到附近的(相对)元素。这些是:

  • oLeftOf() : Element located to the left of specified element.
  • toRightOf() : Element located to the right of the specified element.
  • above() : Element located above with respect to the specified element.
  • below() : Element located below with respect to the specified element.
  • near() : Element is a range of at most 50 pixels from the specified element. The pixel value is adjustable

8. Selenium WebDriver中有哪些不同的等待?(What are the different waits in Selenium WebDriver?)

There are three types of waits in WebDriver:

WebDriver中有三种类型的等待:

  1. Implicit Waits: This is a wait timeout that applies to an instance on a WebDriver. It implies that all actions of this instance are time-out only after waiting for a period of time.
  2. Explicit Waits: This is an exclusive time-out method that works by adding code to delay the execution until a specific condition arises. It is more customizable in terms that we can set it up to wait for any suitable situation. Usually, we use a few of the pre-built expected conditions to wait for elements to become clickable, visible, invisible, etc.
  3. Fluent Waits: This defines the maximum amount of time to wait for a particular condition and frequency to test the condition before throwing an exception to “ElementNotVisibleException.”

9. WebDriver.findElement与WebElement.findElement两者有什么区别?(What is the difference between WebDriver.findElement vs WebElement.findElement?)

  • WebDriver.findElement(): This finds the element from the entire page using the given selector.
  • WebElement.findElement(): First, this generates the WebElement. Then, the child elements of the given element are searched based on the given selector.

10. Selenium框架中的所有设计模式是什么?(What are all the design patterns in the Selenium framework?)

  • Page Object Model (POM) Pattern
  • Factory Pattern
  • Facade Pattern
  • Strategy Pattern

11. 页面对象模型和页面工厂有什么区别?(What is the difference between Page Object Model and Page Factory?)

  • Page Object Model (POM): POM is a Selenium design pattern. It’s seen as a repository where we store all the WebElements. POM is popular because it’s easy to manage, offers code reusability, and eliminates duplication of code. If UI changes in the future, then we can update WebElements to Page Classes in POM or Object Repository accordingly.
  • Page Factory: Page Factory in Selenium WebDriver is an integrated concept or API. It follows the same principle of keeping repository objects or page classes separate from test classes. Here we use @FindBy to find elements and to initialize WebElements using initElements process.

12. 支持Selenium的定位器有哪些?(What are all the locators that support Selenium?)

  • Name: Same as ID although it is not unique
  • CSS Selector: Works on element tags and attributes
  • XPath: Searches elements in the DOM. Reliable but slow
  • Class name: Uses the class name attribute
  • TagName: Uses HTML tags to locate web elements
  • LinkText: Uses anchor text to locate web elements
  • Partial Link Text: Uses partial link text to find web elements

13. XPath和CSS选择器之间有什么区别?(What are the differences between XPath and CSS Selector?)

  • XPath is slower than CSS Selector
  • XPath supports text, while CSS Selector does not
  • XPath supports index
  • XPath can move in both forward and backward directions whereas CSS Selector can only move forward

14. 如何使用CSS选择器访问第n个元素?(How to access the CSS selector using the nth element?)

Here is a syntax for using the CSS selector to access the nth attribute:  <type>:nth-child(n)

Ex:  tr:nth-child(2)

下面是使用CSS选择器访问第n个属性的语法:<type>:第n个子级(n)

15. 如何处理Selenium WebDriver中的alerts?(How can one handle alerts in Selenium WebDriver?)

WebDriver provides an API to handle alert dialogs.  Alerts cannot able to inspect if there is no Alert in the screen, you will get ‘NoAlertPresentException’

WebDriver提供了一个API来处理alert对话框。如果屏幕中没有警告信息是的Alerts无法进行检查时,将得到“NoAlertPresentException”异常信息。

The Alert interface contains a number of APIs to execute different actions, including: 

Alert接口包含许多用于执行不同操作的APIs,包括:

  • Alert alert = driver.switchto().alert();
  • alert.accept(); This is equivalent to the OK button action on the dialog
  • alert.dismiss(); This is equivalent to clicking on the CANCEL action button
  • alert.sendKeys(“String”); This will allow to type in some text into the alert 
  • alert.getText(); This will return the text that appears on the dialog

16. Selenium WebDriver中有哪些异常?(What are the exceptions in Selenium WebDriver?)

  • WebDriverException
  • NoSuchElementException
  • NoSuchFrameException
  • NoAlertPresentException
  • NoSuchWindowException
  • ElementNotVisibleException
  • ElementNotInteractableException
  • SessionNotCreatedExceptio
  • TimeoutException
  • InvalidSelectorException
  • IllegalStateException
  • StaleElementReferenceException

17. 如何解决Selenium中的StaleElementReferenceException?(How would you overcome StaleElementReferenceException in Selenium?)

Because the reference to an element is now stale the element will no longer appear on the page’s DOM. In other words, the element you located using the findElement method disappeared. 

To resolve this, add exception handling to your action. If the exception is stale, locate the element after a short wait of 500 milliseconds and repeat these actions until the action or max iterations have been successful.

18. What is a framework? What are the different types of frameworks available?

A framework is a charter of rules and best practices for the systemic resolution of a problem. 

There are different kinds of automation frameworks:

  • Data-Driven Testing Framework
  • Keyword Driven Testing Framework
  • Hybrid Testing Framework
  • Behavioral Driven Framework

19. How should one handle Windows-based alerts or pop-ups in Selenium?

Selenium only supports web applications and does not provide a way to automate Windows-based applications. However, the following approach can help.

Use the Java-based Robot class utility to simulate keyboard and mouse actions. The KeyPress and KeyRelease methods simulate the user pressing and releasing a specific key on the keyboard.

20. What are TestNG annotations frequently used with Selenium?

TestNG annotations prioritize the calling of a test method over others. Here are the ones to use with Selenium:

  • @BeforeSuite – to run before all tests
  • @AfterSuite – to run only once after all tests
  • @BeforeClass – to run only once before the first test method
  • @AfterClass – to run only once after all the test methods of the current class finish execution
  • @BeforeTest – to run before any test method inside the “Test” tag
  • @AfterTest – to run after any test method inside the “Test” tag

21. What are Listeners in Selenium?

Listeners is an interface that modifies the behavior of the system allowing customization of reports and logs.

There are two primary types of Listeners, WebDriver Listeners, and TestNG Listeners. 

22. What is a soft assertion and a hard assertion in Selenium?

Soft Assertion: A Soft Assert will not throw an exception when an assert fails and will continue with the next step.

Hard Assertion: A Hard Assert throws an Assert Exception immediately when an assert statement fails and test suite continues with next @Test.

 

 

 

转载地址:http://stvdi.baihongyu.com/

你可能感兴趣的文章
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
linux内核学习(4)建立正式内核的页式内存映射, 以x86 32位模式为例
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>
adb command not found
查看>>
Xcode 启动页面禁用和显示
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Word Break(python)
查看>>