程序代写 Automated Testing Using Selenium

Automated Testing Using Selenium

Automated Testing Using

Copyright By PowCoder代写 加微信 powcoder

https://www.guru99.com/automation-testing.html#1

Automation Testing
Automated Testing Process
Benefits of Automated Testing

1. Automation Testing
Automation Testing means using an automation tool, scripts and software to execute a test case or test suite by repeating pre-defined actions.

When to do automation testing?
Repeat execution of same test – test automation tool allows you to record the test suite and re-execute it when required.
Improves the ROI as no human intervention is required for automated test suits.
Automation testing saves time, as opposed to manual testing and thus increases the speed of testing.
Testing multilingual sites becomes easier using automated testing.
Long test cases can be left unattended in automated testing.
It gives wider coverage of test cases.
Automated testing is less error prone as opposed to manual testing.

Which test cases to automate?
In essence:
High Risk – Cases which are critical to run the business.
Test cases that are repeatedly executed
Test Cases that are very tedious or difficult to perform manually
Test Cases which are time-consuming

Test cases not suitable for automation
Test Cases that are newly designed and not executed manually at least once.
Test Cases for which the requirements are frequently changing.
Test cases which are executed on an ad-hoc basis.

Automation Testing Frameworks
Modular testing framework
Data driven testing framework
Keyword driven testing framework
Hybrid testing framework
Behaviour driven testing framework

Modular Testing Framework
Based on object-oriented programming concepts.
It separates the entire application into a set of logical and isolated modules.
A separate and independent test script is required for each sub-module.
These scripts when put together generate a larger test script that represents multiple modules.
An abstraction layer separates these modules so that changes to portions of application do not affect them.

Data driven testing framework
In application tests, the same functions can be tested with different data sets. It is not a reasonable option to give test data within the automation code.
Retention of data in external databases is a more logical method.
This framework creates a distinction between types of data.
It creates isolated test data by keeping the data in different files.
Data is traditionally stored in “Key/Value” pairs.

Keyword Driven Testing Framework
The keyword-based test framework separates test data from scripts and also allows it to store a specific set of code from the test script to an external data.
In terms of keywords are determined in this code set, and so the framework is named this way.
Test Data and keywords kept in a table-like structure.
Keywords and test data must be assets independent of the automation tool used

Hybrid Testing Framework
The Hybrid Test Frame is a combination of multiple frames.
The best thing about such installation is that it takes advantage of the different frameworks.

Behaviour Driven Testing Framework
The Behaviour Oriented Development framework allows automation in a readable and understandable format for testers. Such frameworks do not require the user to know the programming language.

Automated Test Process

Test Tool Selection
Depends on the technology the Application under test (AUT) is built on.

Planning, Design and Developement
Creation of Automation Strategy and plan.

Test Execution
Testing scripts are executed.

Maintenance
For effectiveness of automation scripts.

Scope of Automation
Area in the Application under test (AUT) which will be automated.

1. Tool Selection

Open course family of Ruby libraries for web browsers.
Watir (Web Application Testing in Ruby)

Commercial
Automates Web and desktop applications
QTP (Quick Test Professional)

Open Source
For automating Web Applications

It’s a good idea to conduct a Proof of Concept of Tool on AUT.

Automation Testing Tool Features

2. Scope of Automation
Features important for the business.
Scenarios that have large amount of data.
Common Functionalities across applications
Technical Feasibility
Complexity of Test Cases
Ability to use the same test cases for cross-browser testing.

You create an automation strategy and plan with the following details:
Automated tool selected.
Framework design and its features
In-scope and out-of-scope items of automation.
Automation testbed preparation.
Schedule and timeline of scripting and execution.
Deliverables of Automation testing.
3. Planning, Design and Development

Framework for Automation
Maintaining consistency of Testing
Improves test structuring
Minimum usage of code
Less Maintenance of code
Improve re-usability
Non-technical testers can be involved in code
Training period of using the tool can be reduced
Involves Data wherever appropriate

A framework is set of automation guidelines which help in :

4. Test Execution
Automated Scripts are executed during this phase.
The scripts need input test data before these are set to run.
Once executed they provide detailed test reports.

5. Maintenance
For new functionalities added during testing or during usage, new automation scripts need to be added, reviewed and maintained for each release cycle.
Maintenance becomes necessary for effectiveness of automation scripts.

Today a test automation expert is expected to design an overall automation strategy for the entire product. They require knowledge to select the right set of tools for every stage and give a cost-effective and unified integration strategy. Automation testers are also expected to develop functions that can reduce manual testing and test data generation work.

Automation Testing Tutorial For Beginners

Web Application Automation Testing Tool

Place your screenshot here

This is the URL that the test will start at. All open commands will be
relative to the Base URL unless a full path is inserted in the open command.
Speed slider – runs tests in Fast/ Slow modes
The Command select box has a list of all the commands that are needed to create a test.
The Target textbox allows you to input the location of the element that you want to work against.
The Value textbox is where you place the value that needs to change (e.g., if you want your test to type in an input box on the web page, you would put what you want it to type in the value box).

With Selenese commands, we can test the existence of
UI elements based on their HTML tags,
test specific content
test for broken links
test input fields, selection list options,
Test table data
submit forms
check window size, mouse position
https://ui.vision/kantu/docs/selenium-ide
Selenese is a testing language (used in Selenium IDE) to write test scripts.

Rules for Automation
Tests should always have a known starting point.
Tests should not have to rely on any other tests to run.
Tests should only test one thing at a time.
Tests should clean up after themselves

Selenium Commands – Actions
Actions: commands that manipulate the state of the application.
eg., “click this link” and “select that option”.
If an Action fails, or has an error, the execution of the current test is stopped.

Some Actions are called with the “AndWait” suffix.
The suffix tells Selenium that the action will cause the browser to make a call to the server, so the test should wait for a new page to load.
e.g. “clickAndWait”.

Selenium Commands – Accessors
Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”.

They are used to automatically generate Assertions.

Selenium Commands – Assertions
Assertions are similar to Assessors, but they verify that the state of the application conforms to what is expected.
e.g., “make sure the page title is X”
“verify that this checkbox is checked”
Selenium Commands are used in 3 modes: “assert”, “verify”, and ” waitFor”.
example, “assertText”, “verifyText” and “waitForText”. 

Validating Items
Assert – this allows the test to check if the element is on the page. If it is not available then the test will stop on the step that failed.

Verify – this also allows the test to check the element is on the page, but if it isn’t then the test will carry on executing.

WaitFor – tells the test to wait for some condition to become true. The test will fail and halt if the condition does not become true within the current timeout setting
waitForPageToLoad

Assertion or Verification
Assert – fails the test and abort the current test case
Verify – fail the test and continue to run the test case.

Choosing between “assert” and “verify” comes down to convenience and management of failures.

Recommended method: Logically group test commands, and start each group with an “assert” followed by one or more “verify” test commands.
Use “assert” first to check if you are on the correct page.
If not on the correct page, then abort the test case so that you can investigate the cause and fix the issue promptly. An “assert” to will fail the test and abort the current test case.
If on correct page, use the “verify” to check attributes on the page.

Test Script Syntax
Selenium commands are simple, they consist of the command and two parameters [optional].

Multiple Windows/ Pop ups
Web applications live in many windows of your browser.
Example – A site that shows reports. Each report is shown on a separate window so that the user can easily move between them.

Test Cases and Test Suites
Test Cases are individual tests designed for a specific purpose within a web application.
To save test cases for future use, first save them as Test Cases.
Next save them in different groups called Test Suites.
Now play the entire test suite (which will run all the test cases within that test suite)
Note: Saving a test suite does not save the test case. So, make sure that the test case is saved every time a change is made.

Limitations of Selenium
Selenium uses JavaScript – so operates in technologies which interact with DOM (Document Object Models), such as Silverlight and Flex/Flash applications
Selenium IDE does not work with Canvas elements on the page, so you will not be able to make your tests move items around on a page.
Selenium cannot do file uploads, such as FTP applications

Locators are used to find and match the elements of your page that Selenium test case needs to interact with.
Locators strategies :

Locators – by ID
A control is an element that we can interact with and is not static text.
Elements have an ID attribute, which hold unique ID values.
Selenium finds each item (by ID), and then complete the action that it needs to do against that element.
In the Target textbox this would look like id=“Element”

Locators – by Name
Elements do not necessarily have ID attributes on all of them.
Elements can have names that we can use to locate them.
In the Target textbox this would look like name=Element.

Locators – by Link
The most common element on a page is a link. Links allow pages to be joined together so end users can navigate your site.
link=Continue (4)
link=Cancel (5)

Locators – by XPath
Sometimes elements may not have a suitable id or name attribute. So, we locate these elements by their position on the Webpage.
XPath is the language used for locating nodes in an XML document.
XPath extends beyond simple methods of locating by id/name attributes, such as locating the third checkbox on the page.

Locators – by XPath
Elements can then be located via in absolute or relative terms.
Absolute XPaths contain the location of all elements from the root (html) and are likely to fail with only the slightest adjustment to the application (not advised)

Relative XPaths locates target element based on the relationship with a nearby element with an id/name attribute (ideally a parent element). This is much less likely to change and can make your tests more robust.

XPath examples
xpath=/html/body/form[1] (3) – Absolute path (would break if the HTML was changed only slightly)
//form[1] (3) – First form element in the HTML
 (3) – The form element with attribute named ‘id’ and the value ‘loginForm’
 (3) – First form element with an input child element with attribute named ‘name’ and the value ‘username’
 (4) – First input element with attribute named ‘name’ and the value ‘username’
 (4) – First input child element of the form element with attribute named ‘id’ and the value ‘loginForm’
 (7) – Input with attribute named ‘name’ and the value ‘continue’ and attribute named ‘type’ and the value ‘button’
 (7) – Fourth input child element of the form element with attribute named ‘id’ and value ‘loginForm’

Since only xpath locators start with “//”, it is not necessary to include the xpath= label when specifying an XPath locator.

Locators – by css
CSS (Cascading Style Sheets) is a language for describing the rendering of HTML and XML documents.
CSS uses Selectors for binding style properties to elements in the document. These Selectors can be used by Selenium as another locating strategy.

CSS Examples
css=form#loginForm (3)
css=input[name=”username”] (4)
css=input.required[type=”text”] (4)
css=input.passfield (5)
css=#loginForm input[type=”button”] (7)
css=#loginForm input:nth-child(2) (5)

Locators – by DOM
The Document Object Model represents an HTML document and can be accessed using JavaScript. This location strategy takes JavaScript that evaluates to an element on the page, which can be simply the element’s location using the hierarchical dotted notation.
Since only dom locators start with “document”, it is not necessary to include the dom= label when specifying a DOM locator.

DOM examples
dom=document.getElementById(‘loginForm’) (3)
dom=document.forms[‘loginForm’] (3)
dom=document.forms[0] (3)
dom=document.forms[0].username (4)
dom=document.forms[0].elements[‘username’] (4)
dom=document.forms[0].elements[0] (4)
dom=document.forms[0].elements[3] (7)

What we covered?
Automation Testing
Automated Testing Process
Benefits of Automated Testing

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com