Basics of Selenium automated testing from entry to proficiency

What is automated testing?

Automated testing is a testing method that replaces the execution of a large number of use cases that require manual regression by computers.
That is: use scripts to control the computer to open web pages, click links, enter text, click buttons, etc. to simulate a series of manual operations, capture and judge whether the results meet expectations. Advantages
:

  • Save a lot of manpower
  • fast execution
  • Can take advantage of night and weekend execution
  • Facilitate continuous integration and continuous delivery

shortcoming:

  • Developing automated test cases requires a certain cost (high cost, long cycle)
  • Not well suited for projects that iterate quickly
  • Generally, it is necessary to intervene in automation when the project and UI are stable
  • Automated testing generally executes the original fixed logic, and it is not easy to find new bugs
  • There will also be bugs in automation use cases, which will interfere with problem location
  • Unstable test environment and automation framework will cause many invalid tests

Intervention conditions for automated testing

  1. Manual testing cannot be done and requires a lot of time and manpower
  2. The demand changes infrequently and is relatively stable
  3. The project cycle is long enough
  4. Automated test scripts can be reused
  5. Manual testing basically passed

automated testing tools

Here are two more commonly used automated testing tools

  • Selenium: An open source browser automation framework that simulates browser operations and supports multiple languages
  • QTP: An old-fashioned automated testing tool from HP, with powerful recording functions and object libraries, easy to use

Comparison of Selenium and QTP

focus point Selenium QTP
Whether to charge open source, free business, charge
Development language Python、Java、C#、PHP等 VBS
Supported browsers Chrome、IE、Firefox,Safari、Android等 IE、Firefox
supported platforms Windows、Linux、Mac Windows
scalability Strong scalability poor scalability

Selenium installation

  1. Install Python3 (pip is installed by default and environment variables are added)
  2. pip install selenium
  3. Install the latest version of Chrome
  4. Download the latest version (v2.43) of chromedriver.exe and put it in the Scripts folder of the Python installation directory

Download address:  CNPM Binaries Mirror

  1. Test whether the installation is successful, open pycharm, and create a new file demo01.p
from selenium import webdriver 
dr = webdriver.Chrome() 
dr.get("http://www.baidu.com")

Can open the browser and challenge to the baidu page, indicating that the installation is successful

HTML basic knowledge explanation

The webpage we see is actually the source code of the webpage rendered by the browser, html controls the basic layout, css controls the style, and js controls the trigger interaction logic

The most basic HTML structure

<!DOCTYPE html>
<html lang="en">
<head>                            <!--网页标题-->
    <meta charset="UTF-8">
    <title>Title</title>          <!--网页头部信息-->
</head>
<body>
...                               <!--网页主体内容-->
</body>
</html>
  • tag (tag): each <> is a tag, such as html tag, head tag
  • text (text): the text between the tag and the closure (usually the lowest-level leaf tag), such as Title
  • attrib (label attribute): The label can contain familiarity, such as lang="en" is the attribute of the html label

Common attributes: id-page element identification code; class-css style class used by the element; name-variable name when the form element is submitted

HTML Common Elements

  • Link: a tag, the href attribute is the URL of the link, and text is the displayed text, such as: <a href="http://www/baidu.com>baidu
  • Layout: div tag for page layout
  • Table: table label, tr means row, td means cell
  • Form: form tag, used to submit information, etc., buttons, input boxes, radio, check, drop-down boxes, etc. are all elements in the form
  • Frame: iframe tag, the frame web page is actually composed of multiple pages

Use Chrome to view page elements

Open http://www.baidu.com in Chrome browser, press F12 to open the developer tool, click the button in the upper left corner of the developer tool, and then click the input box, you can see the code that locates the element of the input box, the input box is
input label, the id attribute is kw, the name is familiar as wd, and the class is familiar as s_ipt

Practical case

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.

If it is helpful to you, please like and collect it to give the author an encouragement. It is also convenient for you to quickly find it next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and progress with like-minded testers

At the right age, choose the right position, and try to give full play to your own advantages.

My road of automated test development is inseparable from the plan of each stage along the way, because I like planning and summarizing,

Test and develop video tutorials, study notes and receive portals! ! !

Guess you like

Origin blog.csdn.net/m0_59868866/article/details/130014403
Recommended