Selenium and automated testing - "Selenium 2 automated testing real" study notes

background


Recently worked appium, then found a way Selenium framework and this book, just book also introduces some theoretical knowledge of software testing & automated testing, then learn to take over. So this practice is almost no content, mostly mark concepts and tools, if any follow-up practice, I will add.

First, the software testing Category


1, classified according to the project process stages

  • demand analysis

  • design

  • coding

  • unit test

  • Integration Testing

  • System test

  • Acceptance Test

2, white box, black box testing, box testing gray

White-box testing of significance: Sometimes the output is correct, but in fact has an internal error, this situation very much.

Meaning gray-box testing: If every time operated by white-box testing, efficiency will be low, black boxes are too general and therefore compromise the gray box testing is more suitable.

3, functional testing and performance testing

功能测试The main function checks whether the user's actual needs.

Functional test can be subdivided into many kinds: logical functional testing, interface testing, usability testing, installation testing, compatibility testing.


性能测试There are time performance and space performance of two kinds.

Time Performance: mainly refers to a specific response time of the software.

Performance space: mainly refers to the software running the system resources consumed.

4, manual testing and automated testing

Automated testing can not completely replace manual testing , automated testing purpose is to just let testers freed from tedious repetitive testing process them and put more time and energy into a more valuable test, such as exploratory testing. The more automated testing is used to smoke and regression testing.

Automated testing is the focus of this article to explore.

5, smoke testing, regression testing, random testing, exploratory testing and safety testing

冒烟测试: Introduction to software testing, meaning the test team before formal testing a new version, first invested less manpower and time to verify a software main functions , the main functions are not run if passed, hit back to the development team to redevelop. The advantage of this is that you can save time and manpower to undetectable project.

回归测试: Regression testing refers to the old code modified, re-tested to confirm not introduce new bugs or cause other code to generate an error after modification.

随机测试

探索性测试

安全测试

6, the forward and reverse test test

Forward test (Positive Test Case) and reverse test (Negtive test Case) is a classification of test cases.

For example: an input can only accept digital input 0-9, then the use cases may be positive: 0,1,2,3,4,5,6,7,8,9, embodiments may use reverse: other values.

Generally refers to a reverse test, the system does not support the input or the state, such embodiments may be fault tolerance of the inspection system, with the robustness and reliability.

Second, what is automated testing


自动化测试The concept has broad and narrow sense: Broadly speaking, all the way to assist the aid of software testing tools can be called automated testing: the narrow terms, mainly referring to functional test automation based UI layer .

Note: If not otherwise specified herein, "automated testing" means "UI-based functional test automation."

Third, automated testing and hierarchical model


1, the test pyramid

Different test phase invested proportion of automated testing : Unit> Service> UI.

2, Unit layer

Unit Test: The minimum functional module unit under test is artificially predetermined. Standardized unit testing need to use unit testing frameworks such as Junit Java language, TESTNG, Nunit C # language, and Python languages ​​unittest, pytest, at present, almost all mainstream language has its corresponding unit testing framework.

Code Review: Code Review related plug-ins and tools there are many, such as the Java language, the Eclipse-based Review Clipse and Jupiter, mainly for the Python language Review Board and so on.

Now, because of popular github / gitlab, the previous tool is very small. Some manufacturers do not rule out using more professional tools.

Expansion: Code Review

purpose:

1, to improve the quality of the code

Some very basic, such as indentation spaces or something, just to eslint something to solve it.

2, to ensure the team code specifications

3, to improve the code performance

4, bug prevention

5, deepen technical team members to communicate, to create an atmosphere technology

6, old and new mutual growth

Practice recommendations:

1. Review all code must go through in order to merge.

2, when the criticism while giving the best solution

3, each review at least give a positive evaluation to improve confidence in each other

4. Do not discuss requirements in the review of the

5, do not discuss too much architecture or design patterns in the review, this should be addressed early in the design of things

The popularity of the case:

Code Review do well in some of the more common partial technical team, technical team and partial business is relatively small.

Our company has very little to do actually.

3, Service Layer

Interface test: there is a corresponding library or tool, for example Httpunit, Postman other tests of HTTP.

4, UI layer

UI test automation: mainstream testing tools UFT, Watir, Robot Framework, Selenium and so on.

JS automated testing: Qunit Javascript is against a powerful unit testing framework, developed by the jQuery team members, and is used in jQuery, jQuery UI, jQuery Mobile and other projects.

In fact, this is unit testing, but because it is the front end, so go to the UI side.

Fourth, what kind of projects suitable for automated testing


(1) software requirements change frequently

Or the first approach is a compromise of the system is relatively stable and functional modules for automated testing, and changes in the larger part of the test by hand.

(2) the project cycle is longer

(3) Automated test scripts can be reused

(4) etc.

Fifth, automatic test pattern


1, the linear test

The most primitive method, may exist between test cases repeat the operation will lead to the development and maintenance costs are high.

2, modular test drive

A good solution to the problem of duplicate script.

3, the data driving test

Because the input to cause various different output data . To achieve the separation of data and scripts.

4, keyword-driven testing

After understanding the data-driven, it is that the "data" with "keyword", cause the results to vary by changing keyword .

benefit:

Currently on the market typical keyword-driven tools QTP (now renamed UFT- Unified Functional Testing), Robot Framework (RIDE) based tools. Such tools encapsulates the underlying code available to users independent graphical interface, in the form of "fill in the form" exemption testers fear of writing code , thereby reducing the difficulty of writing the script, we simply use the keyword tools provided as to "process" type of embodiment can be written.

harm:

Keywords drive can also write to write code like the same use case, in the programming world, nothing can not do: but this is the same use case requires a high learning costs, and learning a programming language almost equal . Such a framework more to the latter the more difficult maintenance, reliability will deteriorate, the use of keywords and experience within the confines of your own framework, you've learned it is difficult to reuse elsewhere . So, experience and technology accumulated value of testers is concerned, I prefer to develop automation scripts directly programmatically.

Sixth, automated testing tools - selenium 2 (UI layer)


Chapter practical operation portion omitted, if subsequent practice, will be appropriate to add.

Some people say that our company is a software language development, automated testing so have to choose a language: in fact, software development languages and software test automation language not necessarily linked . In other words, based on Python (+ Selenium) automated test scripts written in either test Java-based Web development project, you can test PHP-based Web development projects. Therefore, the choice of language Selenium automated testing does not need to consider consistency with the development of language.

1. What is selenium 2

selenium 2 It is a web browser test automation framework.

all referring to the following default selenium selenium 2.

Although selenium support Android automated testing, but more is recommended Appium, Appium is an extension of selenium, basically can be regarded as " Selenium for Apps ", because it is also based on the Selenium Webdriver technology development.

2, selenium history

selenium (selenium 1) and webdriver turned out to be two different open source projects, but in selenium 2, when the selenium and webdriver merged, namely:

selenium 2 = webdriver + selenium 1

So selenium 2 can be equivalent to webdriver, for Selenium 2 study, in fact, is to learn to WebDriver API's.

3, selenium support model

selenium support HtmlUnitand PhantomJStwo modes.

Phantom JS is a Javascript API's have no interface Webkit core, with Htmlunit similar, but more advanced than some of it.

Automatic test run carried out by or Phantom JS HtmlUnit not really open a browser, in our view, we can see what will think it is real, when necessary, can call the shots in the api.

4, install selenium

pip3 install selenium

5, common functions

  • Control the browser: If the window is resized

  • Find elements (positioning)

  • Operating elements

  • Mouse Events

  • Keyboard Events

  • Set elements waiting

  • Multi-frame, iframe switching / multi-window switch

    Call switch_to.frame()andswitch_to.window()

  • Processing alert box
    where the recipient of the alert box:driver.switch_to_alert().accept()

  • Upload / download files
    more complicated upload / download scripts need to write Autoit

  • Operation Cookie

  • JS call
    callexecute_script()

6、Selenium IDE

Provided in the form of a browser plug-in.

Function Point NOTE:

1, the difference between assertion and verification: the 断言comparison, when the execution 验证command failure does not terminate the test.

2, the difference between the pause and waitfor: dormancy pause setting a fixed time, and to wait for an element waitfor is displayed within a certain time.

3, support for recording content export to the code, the type of support as follows:

Ruby/Rspec/Webdriver

Ruby/Rspec/Remote Control

Ruby/Test: Unit/ Webdriver

Ruby/Test: Unit/Remote Control

Python/unittest/Webdriver

Python/unittest/Remote Control

Java/Junit4/Webdriver

Java/Junit4/Webdriver Backed

Java/Junit4/Remote Control

Java/Junit3/Remote Control

Java/TESTNG/Remote Control

C#/Nunit/Webdriver

C#/Nunit/Remote Control

7、Selenium Grid 2

(1 Introduction

Selenium Grid 2 can use to establish a master node (Hub) on different hosts and the branch node (Node) , the test can be made the primary node running on a different branch node. On different nodes, you can set up different test environments (operating system, browser), so that the results of a test to be implemented in different environments.

(2) Installation

Selenium Grid 2 when no longer offer a separate package, its function has been integrated into the Selenium Server in, so you need to download and run Selenium Server can use the function Bio Grid 2's.

Selenium Grid 2 are hereinafter referred to as Selenium Grid.

(3) Improvement disadvantages

Selenium Grid only provides multi-system, multi-browser execution environment, Selenium Grid itself does not provide parallel execution of test cases. It is recommended that the use of multi-threading technology combined with Selenium Grid to implement distributed parallel execution of test cases .

Seven automated testing tools - unittest (python unit testing framework)


There are many unit testing framework in Python language, such as doctest, unittest, pytest, nose and the like, unittestthe frame (formerly Pyunit frame) of the Python language comes unit testing framework , Python 2.1 and later versions have as a unittest standard development Kit module into Python.

1, the concept of

单元测试By itself is a piece of code to verify another piece of code.

(1)Test Case

The example is a Testcase a 测试用例.

  • A use case is a complete scene , to the final exit from the user log in and close the browser.

  • A use case validation only a function point , do not attempt after the user logs all the system functions to verify again.

  • With possible use cases between cases to avoid dependence .

  • After the test scenarios need to be a complete test case reduction , so as not to affect the execution of other use cases.

(2)Test Suite

A verification function often require multiple test cases, you can put a set of multiple test cases together to perform, which resulted in the 测试套件concept of Testsuite.

(3)Test Runner

It contains the results of the implementation strategy and execution.

(4)Test Fixture

For a test environment to build and destroy , it is a fixture.

2, using

To be written

3, generate HTML test report

HTMLTestRunner Is an extension of unittest, it generates easy-to-use HTML test report.

To be written

4, shortcomings

Selenium Gird with the above said, like, unittest unit testing framework itself does not support multi-threading technology , it can not be like the TESTNG Java frameworks through a simple configuration to use multi-threading technology to execute test cases.

Eight, advanced automated test applications


1, the automatic email function

SMTP (Simple Mail Transfer Protocol) is the Simple Mail Transfer Protocol.

Python's smtplibmodule provides a convenient way to send e-mail.

The test may be used to inform the results.

2, Page Object Design Pattern

Page 对象(Page Object)A basic rule of thumb is: whatever people can do, page objects through software clients are able to do. Thus, it should provide an easy programming interfaces and hides the underlying window member. So access a text box should be achieved through an access method (accessor method) to obtain the return of the string , boolean value check box should be used, the button should be expressed as a behavior-oriented method name. page object shall conduct all queries and operations as data encapsulation method on GUI controls . A good rule of thumb is to change even if the specific controls, connectors paee object does not change should occur.

You can also create a base of the Page object, so that other page inherit it.

Interface and implementation of object-oriented programming ideas in the face like.

Nine, automated testing project combat


To be written

Guess you like

Origin www.cnblogs.com/xjnotxj/p/11520983.html