`

Selenium Tutorial -4 How to Use Firebug for Creating Selenium Scripts

 
阅读更多

http://www.softwaretestinghelp.com/firebug-for-selenium-scripts-selenium-tutorial-4/

 

In the previous tutorial, we learned how to create automated test scripts using Selenium IDE and its recording feature. We also flipped through populous features of Selenium IDE. We aimed at harbingering the reader with the most vital features and commands of Selenium IDE.

Just a reminder – this is our 4th tutorial in free Selenium training series.

Now that you are accustomed and capable of creating automated scripts using recording mode of Selenium IDE, let us move ahead with another tool which plays a very important role in assisting us to create effective test scripts known as “Firebug”. Firebug helps us in inspecting the properties of web elements and web pages.

Thus, this tutorial is comprised of installation of Firebug and its usability.

Selenium script using Firebug

Take a note that the content of this tutorial is not only applicable in context of Selenium IDE; rather it can be applied to each and every tool of Selenium suite. Thus I would preferably be using term Selenium instead of Selenium IDE.

In this tutorial lets learn how to use Firebug add-on for creating Selenium scripts. In the process we will also learn how to install Firebug.

Introduction to Firebug

Firebug is a Mozilla Firefox add-on. This tool helps us in identifying or to be more particular inspecting HTML, CSS and JavaScript elements on a web page. It helps us identifying the elements uniquely on a webpage. The elements can be found uniquely based on their locator types which we would be discussing later in this tutorial.

How to Install Firebug?

For the ease of understanding, we would bifurcate the installation process into the following steps.

Step -1: Launch the Mozilla Firefox browser and navigate to thisFirebug add-on download page. The URL takes us to Firefox add-ons section.

Step -2: Click on the “Add to Firefox” button present on the webpage. Refer the following figure for the same.

install firebug

Step-3: As soon as we click on the “Add to Firefox” button, a security alert box would appear, click on the “Allow” button now.

Step-4: Now Firefox downloads the add-on in the backdrop and a progress bar is displayed.

Step-5: As soon as the process completes, software installation window appears. Now click on the “Install Now” button.

install firebug 1

Step-6: As soon as the installation completes, a pop up appears saying that the firebug has been installed successfully. Now choose to close this pop up.

Note: Unlike Selenium IDE, we are not required to restart the Firefox to reflect the firebug installation, rather it comes readily.

Step-7: Now to launch firebug, we can opt either of the following ways:

  • Press F12
  • Click on the firebug icon present in the extreme top-right corner of the Firefox window.
  • install firebug 2
  • Click on Firefox menu bar -> Web Developer -> firebug -> Open Firebug.

Step-8: Now the firebug can be seen at the bottom of the Firefox window.

Now that we have downloaded and installed firebug, let’s move ahead with the types of locators that we would be creating using firebug.

Creating Selenium Script using Firebug

Unlike Selenium IDE, In Firebug, we create automated test scripts manually by adding multiple test steps to form a logical and consistent test script.

Let us follow a progressive approach and understand the process step by step.

Scenario:

  • Open “https://accounts.google.com”.
  • Assert Title of the application
  • Enter an invalid username and invalid password and submit the details to login.

Step 1 – Launch the Firefox and open Selenium IDE from the menu bar.

Step 2 – Enter the address of application under test (“https://accounts.google.com”) inside the Base URL textbox.

Selenium Script using Firebug 1

Step 3 – By default, the Record button is in ON state. Remember to tune it OFF state so as to disable the recording mode. Notice if the recording mode is in ON state, it may result in recording our interactions with the web browser.

Selenium Script using Firebug 2

Selenium Script using Firebug 3

Step 4 – Open the application under test (https://accounts.google.com) in the Firefox.

Step 5 – Launch Firebug in the web browser.

Selenium Script using Firebug 4

Step 6 – Select the empty test step within the Editor.

Selenium Script using Firebug 5

Step 7 – Type “open” in the command text box present in the Editor Pane. The “open” command opens the specified URL in the web browser.

Selenium Script using Firebug 6

Recommendation: While typing commands in the command text box, user can leverage the feature of auto selection. Thus, as soon as the user types a sequence of characters, the matching suggestions would be auto populated.

User can also click on the dropdown available within the command text box to look at all the commands provided by Selenium IDE.

Step 8 – Now, motion towards the Firebug section within the web browser, expand “head” section of the HTML code. Notice the HTML tag <title>. Thus to assert the title of the webpage, we would require the value of the <title> tag.

Selenium Script using Firebug 7

Copy the title of the webpage which is “Sign in – Google Accounts” in our case.

Step 9 – Select the second empty test step within the Editor.

Step 10 – Type “assertTitle” in the command text box present in the Editor Pane. The “assertTitle” command returns the current page title and compares it with the specified title.

Selenium Script using Firebug 8

Step 11 – Paste the title copied in step 8 into the Target field of the second.

Selenium Script using Firebug 9

Step 12 – Now select the third empty test step in the Editor Pane

Step 13  Type “type” command within the command text box. The “type” command enters a value in the specified web element on to the GUI.

------------

Selenium Script using Firebug 10

Step 14 – Now switch to the web browser, bring the mouse cursor to the “Email” textbox within the login form and press a right click.

Selenium Script using Firebug 11

Choose “Inspect Element with Firebug”option. Notice that the Firebug automatically highlights the corresponding HTML code for the web element i.e. “Email Textbox”.

Selenium Script using Firebug 12

Step 15 – The HTML code in the above illustration manifests the distinct property attributes belonging to the “Email” text box. Notice that there are four properties (ID, type, placeholder and name) that uniquely identify the web element on the web page. Thus it’s up to the user to choose one or more than one property to identify the web element.

Thus, in this case, we choose ID as the locator. Copy the ID value and paste it in the Target field of the third test step prefixed with “id=” to indicate Selenium IDE to locate a web element having ID as “Email”.

(Click to view enlarged image)

Selenium Script using Firebug 13

Make a note that Selenium IDE is case sensitive, thus type the attribute value carefully and precisely the same as it is displayed in the HTML code.

Step 16 – Click on the Find button to verify if the locator selected finds and locates the designated UI element on the web page.

Step 17 – Now, the next step is to enter the test data in the Value textbox of the third test step within the Editor Pane. Enter “InvalidEmailID” in the Value textbox. User can alter the test data as and when it is desired.

Selenium Script using Firebug 14

Step 18  Now select the fourth empty test step in the Editor Pane

Step 19  Type “type” command within the command text box.

Step 20 – Now switch to the web browser, bring the mouse cursor to the “Password” textbox within the login form and press a right click.

Choose “Inspect Element with Firebug”option.

Selenium Script using Firebug 15

Step 21 – The HTML code below manifests the distinct property attributes belonging to the “Password” text box. Notice that there are four properties (ID, type, placeholder and name) that uniquely identify the web element on the web page. Thus it’s up to the user to choose one or more than one property to identify the web element.

Thus, in this case, we choose ID as the locator. Copy the ID value and paste it in the Target field of the third test step prefixed with “id=”.

(Click to view enlarged image)

Selenium Script using Firebug 16

Step 22 – Click on the Find button to verify if the locator tabbed finds and locates the designated UI element on the web page.

Step 23 – Now, the next step is to enter the test data in the Value textbox of the fourth test step within the Editor Pane. Enter “InvalidPassword” in the Value textbox. User can alter the test data as and when it is desired.

Selenium Script using Firebug 17

Step 24  Now select the fifth empty test step in the Editor Pane

Step 25  Type “click” command within the command text box. The “click” command clicks on a specified web element within the web page.

Step 26 – Now switch to the web browser, bring the mouse cursor to the “Sign in” button within the login form and press a right click.

Choose “Inspect Element with Firebug”option.

Selenium Script using Firebug 18

Step 27 – The HTML code below manifests the distinct property attributes belonging to the “Sign in” button.

Choose ID as the locator. Copy the ID value and paste it in the Target field of the third test step prefixed with “id=”.

(Click to view enlarged image)

Selenium Script using Firebug 19

Step 28 – Click on the Find button to verify if the locator picked finds and locates the designated UI element on the web page.

The test script is completed now. Refer the following illustration to view the finished test script.

Selenium Script using Firebug 20

Step 29 – Play back the created test script and Save it in the same way we did in the previous tutorial.

Conclusion

In this tutorial, we introduced yet another script creation tool or rather a tool that aids to script creation.

Firebug surprisingly has a great potential to locate web elements on a web page. Thus the user can leverage the tool’s capabilities in creating effective and efficient automation test scripts manually.

Next Tutorial #5: Moving ahead in the next tutorial, we would have a look at the various types of locators in Selenium and their accessibility technique to build test scripts. In the meantime reader can start building his/her automation test scripts using Firebug.

Have you used Firebug for inspecting HTML elements or for creating scripts? Do you find it useful? Please share your experience in comments

分享到:
评论

相关推荐

    selenium-server-standalone和Selenium-java的jar包

    在这个主题中,我们将深入探讨"**selenium-server-standalone**"和"**Selenium-java**"这两个jar包,以及它们在Java+Selenium自动化测试中的作用。 首先,**selenium-server-standalone.jar**是Selenium WebDriver...

    selenium-server-4.1.1.jar

    Selenium 服务器(selenium-server-4.1.1.jar)

    ruby selenium-client-1.2.18.gem

    4. command prompt go to –&gt; C:\selenium-remote-control-1.0.3\selenium-server-1.0.3&gt;java -jar selenium-server.jar 5. Download the RubyInstaller– The Ruby Installer is currently available only for the ...

    selenium-server-standalone-2.40

    4. **selenium-java-2.40.0.jar**: 这是Selenium Java客户端库的二进制版本,包含了编写Selenium测试脚本所需的类和接口。Java开发者可以将这个JAR添加到他们的项目类路径中,以便使用Selenium提供的API来控制...

    selenium-server-standalone-4.0.0-alpha-2.zip

    标题 "selenium-server-standalone-4.0.0-alpha-2.zip" 指的是 Selenium 的一个服务器独立版本的归档文件,该版本为 4.0.0 的 Alpha 2 版本。Selenium 是一个广泛使用的自动化测试工具,主要用于 Web 应用程序的测试...

    selenium-java-4.0.0-alpha-6_javaselenium_

    4. **selenium-devtools-4.0.0-alpha-6-sources.jar** 和 **selenium-remote-driver-4.0.0-alpha-6-sources.jar**、**selenium-api-4.0.0-alpha-6-sources.jar**、**selenium-support-4.0.0-alpha-6-sources.jar**:...

    selenium-selenium-4.5.0.zip源码

    在 `selenium-selenium-4.5.0.zip` 源码中,我们可以深入理解 Selenium 的内部实现,包括以下关键部分: 1. **WebDriver**: 这部分包含了各个浏览器驱动(如 ChromeDriver、GeckoDriver)的实现,它们作为桥梁,...

    selenium-java-2.44.0、selenium-java-2.44.0-srcs、selenium-server-standalone-2.44.0

    首先,我们来了解一下 `selenium-java-2.44.0.jar`。这是一个预编译的Java库,其中包含了Selenium WebDriver的Java绑定。WebDriver是Selenium的一个核心部分,它提供了一个编程接口,允许测试脚本直接控制浏览器。...

    selenium-server-standalone-3.0.0JAR包

    它的服务器独立版本,即 `selenium-server-standalone-3.0.0.jar`,是 Selenium 的核心组件之一,提供了远程控制浏览器的能力,支持多种浏览器如 Chrome、Firefox、IE 等。 该 JAR 包的版本号为 3.0.0,意味着它是 ...

    selenium-server-standalone-2.44.0.jar

    selenium-server-standalone-2.44.0, selenium最新服务器,

    selenium-server-standalone-3.141.0.jar

    最新版selenium-java,selenium-server-standalone-3.141.0.jar

    selenium-server-standalone-3.141.59

    selenium-server-standalone-3.141.59.jar selenium-server-standalone-3.141.59.jar

    selenium-java-2.45.0.jar

    selenium-java-2.45.0.jar

    selenium-java-2.47.1.zip

    这个压缩包 "selenium-java-2.47.1.zip" 包含了Selenium的Java版本,具体是2.47.1的更新,发布于2015年8月。这个版本在当时是一个稳定且广泛使用的版本,它提供了丰富的API,支持多种浏览器,并且可以与各种测试框架...

    selenium-server-standalone-2.45.0和selenium-java-2.45.0(含srcs)

    "selenium-server-standalone-2.45.0" 和 "selenium-java-2.45.0(含srcs)" 提供了Selenium在Java环境下的核心组件,以及一个独立的服务器版本,方便进行Web应用的自动化测试。 1. **Selenium Server Standalone**...

    selenium-4.1.0-py3-none-any.whl

    selenium-4.1.0-py3-none-any.whl

    selenium-server-standalone-3.4.0&selenium;-java-3.4.0.jar

    这个标题提到的是 "selenium-server-standalone-3.4.0" 和 "selenium-java-3.4.0.jar",它们是 Selenium 3.4 版本的组成部分,专为 Java 开发者设计。下面将详细阐述这两个文件及其在测试中的作用。 `selenium-...

    selenium-htmlunit-driver-2.9.0

    selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包

    selenium-server-standalone-3.9.1.jar

    selenium-server-standalone-3.9.1.jar,python插件,用于web自动化测试

    selenium-server-standalone-3.9.1.rar

    "selenium-server-standalone-3.9.1.rar" 文件包含了Selenium Grid 的独立服务器版本,适用于3.9.1这个高版本。Selenium Grid 是Selenium工具集中的一个重要组成部分,它允许我们进行分布式自动化测试,提高测试效率...

Global site tag (gtag.js) - Google Analytics