Selenium automated testing foundation

table of Contents

What is automated testing?

Automated testing is the need to manually return a large number of use cases for testing by the computer instead of the modalities of implementation.
Namely: computer control using a script open the page, click on the link, enter text, click the button to manually perform a series of operations such as analog, crawl and determine whether the results in line with expectations of process
advantages:

  • Save a lot of manpower
  • Execution speed
  • It can be used at night and on weekends to perform
  • Facilitate continuous integration and continuous delivery

Disadvantages:

  • Development of automated test cases need some costs (high cost, long cycle)
  • Not suitable for rapid iteration of the project
  • General need in order to intervene in the automation project stability and UI
  • Automated testing is generally performed original fixed logic, not easy to find a new bug
  • Automation cases there will be bug, locate the problem will cause interference
  • Unstable environment and test automation framework will cause a lot of times the test is invalid

Involved in automated testing conditions

  1. Manual testing can not be completed, it requires a lot of time and effort
  2. Requirements change frequently, relatively stable
  3. Project period is long enough
  4. Automated test scripts can be reused
  5. The basic manual testing by

Automated testing tools

This introduces two commonly used automated testing tools

  • Selenium: an open source browser automation framework, simulation browser operations, support for multiple languages
  • QTP: HP company a veteran of automated testing tools, with powerful recording functions and the object library, easy to use

Comparison of Selenium and QTP
| concerns | Selenium | QTP |
| ---------- | ------------- | ------- |
| whether charges | open source, free | commercial costs |
| programming language | Python, Java, C #, PHP , etc. | VBS |
| supported browsers | Chrome, IE, Firefox, Safari , Android , etc. | IE, Firefox |
| supported platforms | Windows, Linux, Mac | Windows |
| scalability | scalability | poor scalability |

Selenium installation

  1. Installation Python3 (the default installation pip and add environment variables)
  2. pip install selenium
  3. Install the latest version of Chrome
  4. Download the latest version (v2.46) of chromedriver.exe, into Python installation directory Scripts folder
    Python / Scripts directory

Download: http://npm.taobao.org/mirrors/chromedriver/

  1. Test whether the installation was successful, open pycharm, New File demo01.py
    Scripting
from selenium import webdriver

dr = webdriver.Chrome()
dr.get("http://www.baidu.com")

Can open the browser and to challenge baidu page, it indicates the installation was successful
Open a browser window and access Baidu

html explain the basics

We see web page source code is actually rendered by the browser, html control basic layout, css styles control, js trigger interactive logic control

The most basic HTML structure

<!DOCTYPE html>
<html lang="en">
<head>                            <!--网页标题-->
    <meta charset="UTF-8">
    <title>Title</title>          <!--网页头部信息-->
</head>
<body>
...                               <!--网页主体内容-->
</body>
</html>
  • Tag (label): each <> as a label, such as html tags, labels head
  • text (Text): intermediate closing tag (generally the most subordinate leaf tag) of text, such as Title
  • Attrib (tag attributes): familiar tag can contain, as lang = "en" is an attribute of tag html

    Common attribute: id- page element identifier; the variable name when name- form elements submitted; css style class class- used elements

Common HTML elements

  • Link: a tag, the href attribute is the URL link, text is displayed in the text, such as: <a href=" http://www/baidu.com> baidu
  • Layout: div tags for page layout
  • Table: table label, tr represents a row, td represents a cell
  • Form: form tag for submitting information, buttons, input boxes, radio, check, drop-down box in the form of elements belong
  • Framework: iframe tags, page frame is actually made up of multiple pages

View page elements using Chrome

Chrome browser to open http: /www.baidu.com, press F12 to open the Developer Tools, click the top left corner of the Developer Tools button, and then click the input box, navigate to the code input box elements
Positioning input element
can be seen, the input box to input labels, id attribute kw, name familiar to wd, class familiar to s_ipt

Guess you like

Origin www.cnblogs.com/superhin/p/11454918.html