Selenium Browser Automation test usage (1)

Source: Internet
Author: User
Tags glob selenium grid

Selenium-Introduction

Selenium is an open source and portable automated software Testing tool for testing Web applications that are capable of running in different browsers and operating systems. Selenium is really not a single tool, but a set of tools that help testers automate web-based applications more effectively.

Now let's understand the selenium suite and use these tools. We will focus on the following tool features:

Tools Description
Selenium IDE The Selenium integrated Development Environment (IDE) is a Firefox plug-in that allows testers to follow a workflow that requires testing to record their behavior.
Selenium RC Selenium remote Control (RC) is the flagship test framework that allows multiple simple browser actions and linear execution. It uses the programming languages such as Java,c#,php,python and the powerful features of Ruby and Perl to create more complex tests.
Selenium Webdriver Selenium's webdriver predecessor is Selenium RC, which sends commands directly to the browser and retrieves the results.
Selenium Grid The selenium grid is used to run parallel testing tools on different machines, different browsers simultaneously to minimize execution time.
Selenium advantages

QTP and selenium are the most common tools for software automation testing on the market. Therefore, selenium has more significance, now selenium compare qtp/uft have more advantages.

Selenium qtp/uft
Selenium is an open source tool. QTP is a business tool and costs involved in licensing.
It can be extended to expose dom various techniques. Limited add-ons and technologies that require additional components.
Scripts can be executed in different browsers. You can run tests on specific versions of Firefox,ie and Chrome browser.
You can execute scripts for various operating systems. Applies only to Windows operating systems.
Supported mobile devices. Mobile devices that support third-party tools.
Performing tests in the browser, which is not required, focuses on the progress of the script execution. Script execution tools need to focus on the browser (simulating user actions)
You can run tests in parallel using the selenium grid. QTP cannot perform tests in parallel, but integration with quality control QTP allows testing to be performed in parallel. Quality control is also a business tool.
Selenium Disadvantages

Now we are discussing the selenium of the more qtp defects.

Selenium qtp/uft
Only web-based applications are supported. You can test Web and desktop applications.
Any feature, such as Object repository/recovery scenario QTP has been or is built into the recovery scheme.
There is no IDE, so this script development is not faster than QTP. More intuitive IDE, automation, can be achieved faster.
Cannot access control in the browser You can access controls in the browser, such as the Favorites bar, back and forward buttons.
No test reports are generated by default. The default test results in the build tool.
For parameter settings, the user must be dependent on the programming language The parameters are built-in and easy to implement.

Selenium-ide

Selenium IDE (integrated development environment) is an easy-to-use Firefox plugin for developing selenium test cases. It provides a graphical user interface for recording using the Firefox browser to learn and use selenium user actions, but it can only be used for Firefox browsers that do not support other browsers.

However, the recorded scripts can be converted to support multiple programming languages by selenium and scripts can be executed in a variety of other browsers as well.

Click on the table to learn more about each of the features listed below.

Title Description
Download Selenium IDE This section describes how to download and configure the selenium IDE
Selenium IDE Features This section describes the features that are used in the Selenium IDE
To create a selenium IDE test This section describes how to use the logging feature to create an IDE test
Selenium IDE Script Test This section describes the debugging of selenium IDE scripts
Inserting verification points The Selenium IDE insert validation is discussed in this section.
Selenium Pattern Matching This section describes how to work with an IDE regular expression.
Selenium User Extensions Java scripts that allow users to customize or add new functionality.
No browser execution This section describes how to execute Selenium IDE scripts in different browsers.

Selenium-ide

Step 1: start Firefox, then navigate to url-http://seleniumhq.org/download/. In the Selenium IDE section, click the link that displays the current version number as shown below.

Step 2: Firefox's add-ons notification pops up with the Allow and disable option. The user must allow the installation.

Step 3: Add-on installer warns the user of untrusted add-ons. Click "Install Now".

Step 4: Selenium IDE can now access ' Tools ' >> ' Selenium ide ' by browsing.

Step 5: in the Selenium IDE, you can also access directly from the Quick Access menu bar as shown in.


Selenium-ide Tool Features

The features of the Selenium IDE List a simple tool with the help of hints, as shown in.

The functions of the Record toolbar are described below.



Selenium IDE Test Creation

Involves creating tests using IDE selenium, such as the following steps

    1. Logging and testing Add commands

    2. Save Test Records

    3. Save test program

    4. Execute Test record

Record and add commands in a test

For demonstration purposes, we will use www.ncalculators.com to understand the characteristics of selenium.

Step 1: launch the Firefox browser and navigate to the website-http://www.ncalculators.com/

Step 2: Open the Selenium IDE from the Tools menu, press the Record button-that is, in the upper right corner.

Step 3: navigate to "Math Calculator" >> "Percent Calculator >> Enter" 10 "as number1 and enter 50 as number2 and click on" Cal Culate ".

Step 4: Then, the user can insert a checkpoint by right-clicking the Web element and selecting "Show all available Commands" >> Select "Assert text Css=b 5"

Step 4: The recorded script is generated and displayed in the following script as shown below.

Test for saving Records

1th Step: Save the test case by navigating to "file" >> "Save Test" and saving the file in the selected location. The file is saved as. HTML is the default value.

The test can also save the extension. Htm. sHTML and. XHTML.

Save Test suite

A test suite is a collection of tests that can be performed as a separate entity.

Step 1: Create a test suite by navigating to "File" >> "New test suite" as shown below:

Step 2: the test can be recorded by selecting options, one after another from the "File" menu of "New test Case".

Step 3: personal tests use a separate name to save "Test Suite".

Perform a recorded test

The recorded script that executes any script can be done by clicking the button "Play entire Suite" or "Play current Test" in the toolbar.

1th Step: The running state can be seen in the pass and failed test number status pane that is displayed.

2nd step: Once the step is executed, the user can see the result in the "Log" pane.

3rd step: After each step, the background of the test step becomes "green" if it is passed if the failure is "red", as shown in.




Selenium IDE Test

debugging is to discover and fix test scripts, and the common steps of any script development are the wrong handling. To make this process more robust, we can use a plugin from the selenium IDE called "Power Debugger"

Step 1: Install the Selenium IDE's power Debugger and navigate to https://addons.mozilla.org/en-US/firefox/addon/ power-debugger-selenium-ide/then click on the "Add to Firefox" link as follows:

Step 2: Now launch ' Selenium IDE ' will send a new icon, "Pause on Fail" in the Recording toolbar as shown in. Click it to ON. When you click again, open it as "OFF".

Step 3: The user can open "pause on fail" to open or close at any time even if the test runs

Step 4: Once the test is paused, because there is a failure in the step, you can continue the test using the usual pause/step button. If the failure is in any test case, the last command execution will not be paused.

Step 5: We can also use breakpoints to understand what's going on in this process. Insert a breakpoint on a specific step, execute from the context "right-click" and select "Toggle Break Yiibai" related menu.

Step 6: Inserting a breakpoint Displays the pause icon, as shown in the specific steps below.

Step 7: When we execute the script, the script pauses execution where the breakpoint is inserted. This will help to calculate the value/representation of an element and so on during user execution.



Selenium-ide Pattern Matching

In the selenium IDE, such as a locator, a pattern is a type of parameter that is often used in selenium. It allows the user to describe the pattern of special characters. Many times, we want to verify that the text is dynamic, in which case pattern matching is very useful.

Pattern matching is used for all authentication point commands-Verifytextpresent,verifytitle,verifyalert,assertconfirmation,verifytext and Verifyprompt

There are three ways to define a pattern-wildcards, regular expressions, and precision.

Wildcard characters

The wildcard has a file matching mode that is already in use in Linux or Windows, while looking for a specific file type, such as * Doc or *. JPG, most technicians. But the selenium only supports three special characters: *,? and [].

    • *-matches any number of characters.

    • ? -Matches a single character.

    • []-the so-called character class, which can match any single character found in parentheses. [0-9] Match any number

To specify the selenium command glob, prefix the keyword with the pattern ' glob: '. For example, if you want to search for the text "tax year 2013" or "tax year 2014," You can use "tax year *" instead, as shown in.

However, the usage of the keyword "glob:" is optional, and the text pattern is specified, because the selenium matching mode is the default.

Command Target value
Clickandwait Link=search
Verifytextpresent Glob:tax Year *
Precision Mode

The pattern is prefixed with "exact:" to match the given text. The user wants the string value to match exactly, i.e. without the globe operator, we can use the "exact" pattern as shown. In this example, the operator ' * ' will be used as a normal character instead of a pattern-matching wildcard.

Command Target value
Clickandwait Link=search
Verifyvalue Exact: *.doc
Regular expression pattern

Regular expressions are the most useful of the patterns that are available in the matching technique. Selenium supports the full Java language Support Reugular expression mode. Therefore, the user is no longer limited by the *,? and [] Match mode.

To use the regular expression pattern, we need to "regexp:" or "regexpi" with any prefix. The prefix "REGEXPI" is case insensitive. Glob: and exact: The pattern is a subset of the regular expression pattern. Everything is done using glob: and exact: can be done with regular expressions.

Example

For example, the following will test if the field that is entered with the ID "name" contains the string "Tax year", or ' tax year '.

Command Target value
Clickandwait Link=search
Verifyvalue Id=name Regexp:[tt]ax ([Yy]ear)


Selenium User Extensions

It's easy to extend the Selenium IDE to add custom actions, assertions and positioning, policies, which are selenium object prototypes by adding methods, with the help of JavaScript. At startup, selenium automatically looks through these prototype methods, using the name pattern to identify which actions, assertions, and locators are.

Let's use JavaScript to add a ' while ' loop in the selenium IDE.

Step 1: to add a JS file, first navigate to https://github.com/darrenderidder/sideflow/blob/master/ Sideflow.js and copy the script and location to save it in the local folder as "Sideflow.js" as shown in.

2nd step: Start the Selenium IDE now and navigate to options >> options as shown in.

3rd Step: Click on the "Selenium Core Extensions" area under the "Browse" button and point to the JS file we have saved in step 1th.

4th step: Restart the selenium IDE.

5th step: Now there will be a chance to get some more commands, such as "Label" "while" and so on

6th step: Now, we create a loop within the Selenium IDE, which is capable of executing as shown in.



Selenium ide-different browsers

The Selenium IDE script only runs tests on Firefox's tool Firefox plugin. Tests developed with Selenium-ide can be performed on remote control scripts that other browsers save as selenium network drives or selenium. The script can only run tests on Firefox's tool Firefox plugin. Tests developed with Selenium-ide can be performed on remote control scripts that other browsers save as selenium network drives or selenium. More on the remote control of selenium's webdriver and selenium, which is explained in detail in the following chapters.

1th Step: Open the Selenium IDE for any saved tests

2nd Step: Navigate to the "File" menu and select "Export Test Suite as" and the selection will be listed.

Step 3: Now let's export the script "Webdriver" and save it as the same name.

4th step: as shown, the Save Webdriver file is displayed.





Selenium Browser Automation test usage (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.