How to use python for automated testing?

First of all, you have to know the python programming language. It takes a week or two to learn the basics of python programming. What content does the basics of python programming generally contain?

  • An introduction to Python, the installation of python, and the construction of the environment.
  • Learning of Python coding standards and data types.
  • Learning of common control statements and syntax in Python.
  • Python object-oriented programming.
  • Python function application
  • Python graphical interface introduction GuiTkinter
  • Python exception handling and input and output
  • Python programming project practice
     

After having a certain programming experience, the next step is to start testing with the help of automated tools.

Secondly: learn an automated testing tool, the most common tools based on web testing are: selenium, based on App testing: Appium testing tools, these two testing tools are used for automated testing on mobile and web respectively, with the help of Python Language or JAVA language to carry out automated testing.

What knowledge do we need to learn to learn Selenium testing tools?

Build an automated test environment

  1. Copy the driver and seleniumjar packages to the lib folder.

  2. Configure the build path and add the selenium jar package

  3. Configure the startup path of the Firefox browser and the path of the driver.

Write keyword methods based on the automated test environment, and use keyword-driven scripts to execute automated tests.

Some commonly used operations in the test process are encapsulated as method keywords, which is convenient for subsequent scripts to call. It makes script management more logical and easier to maintain.

The role of writing keywords data-driven: Using keywords can make scripts more readable, more logical, and easier to maintain.

insert image description here

Again: The core content of WEB automated testing for front-end pages lies in element encapsulation.

Detailed explanation of element positioning method:

1. Determine the elements you want to operate, unless there are some special scenarios that require similar elements to be operated in batches.

2. The element starts with <element name> and ends with </element name>.

3. Element hierarchy: parent element, child element, sibling element.

Commonly used methods when positioning elements are:

id : An attribute that uniquely identifies an element.

name : name.

·linktext: Locate according to the full text of the hyperlink and match it exactly.

·partiallinktext: Fuzzy matching, locate with partial text of hyperlink.

Used for positioning with hyperlink text, only applicable to a tags.

· classname: makeup. The name of the CSS style.

· tagname: element name. Equivalent to the classification of people.

The element positioning method is shown in the figure below:

Finally: Write automated test scripts based on python language and selenium test tools, and generate automated test reports as shown in the figure below:

insert image description here

 

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you! Partners can click the small card below to receive  

Guess you like

Origin blog.csdn.net/chengxuyuznguoke/article/details/130329144