Automated testing python interview questions

Eight element positioning methods

Question: There are several commonly used positioning methods for elements. What are they? Which one is your favorite and why?

1. ID positioning: ID is the only one in the current entire HTML page, so elements can be positioned through the ID attribute, which is the preferred element positioning method.

2. Name positioning: Position attributes based on the name of the element, but name is not unique.

3. Class positioning: Positioning using the class attribute of the element cannot uniquely locate an element. When there are spaces in the class attribute value, when positioning using all class attribute values, the spaces must be replaced by dots; when there are spaces in the class attribute value, the class attribute values ​​can be separated by spaces, and part of the separated class attribute values ​​can be used for positioning.

4. tag_name positioning: tag_name is positioned by the tag name, such as tag. Tag names will be repeated, and the first matching element is returned by default.

5. Link_text positioning: link_text can only use precise matching (the entire text content of the tag) and must be positioned based on the complete text content on the link.

6. Partial_link_text positioning: You can use precise or fuzzy matching. If you use fuzzy matching, it is best to use a unique keyword; if there are multiple values, the first value will be returned by default.

7. xpath positioning:

Positioning method one (absolute path)

Positioning method two (relative path)

Positioning method three (path combined with attributes): syntax //input[@id='id value'].

Positioning method four (text content matching): syntax //a[text()="news"], the label is a and the text information is "news".

Positioning method five (part of the text information contains matching): syntax //a[contains(text(),"新")] or //a[contains(text(),"smell")].

Positioning method six (path combination logic): Syntax // tag name [@attribute name = 'attribute value' and @attribute name = 'attribute value'].

Positioning method seven (locating child elements through parent): Syntax // tag name (or *) [@parent attribute name = 'parent attribute value']/input.

Positioning method eight (direct copy method): Right-click the manually positioned label to copy the xpath element, and copy it directly into the code.

8. CSS selector positioning: Use element cascading style positioning

 In css positioning, you can use any attribute of the element to position the element.

 In css positioning, you can add a dot in front of the value to indicate that the class attribute value is used for positioning.

In css positioning, you can add # in front of the value to indicate that the id attribute value is used for positioning.

Automated waiting

Question: What are the three types of waits in automation, and what are their characteristics?

1) Thread waiting (forced waiting) such as time.sleep(2): The thread is forced to sleep for 2 seconds. After 2 seconds, the subsequent code will be executed. It is recommended to use sparingly.

2) imlicitlyWait (implicit wait) will continue to search for elements within the specified time range until the element is found or times out. The characteristic is that you must wait for the entire page to be loaded.

3) WebDriverWait (explicit wait) is usually a function code we customize. This code is used to wait for a certain element to be loaded before continuing to execute subsequent code.

Python’s garbage collection mechanism

Question: What is the garbage collection mechanism in python?

When defining a variable, memory space will be applied for. When the variable is used up, the memory space occupied by the variable should also be released, and Python will be recycled by the garbage collection mechanism.

No matter what kind of garbage collection mechanism, it is generally divided into two stages: garbage detection and garbage collection.

Garbage detection is to distinguish between "recyclable" and "non-recyclable" memory in allocated memory.

Garbage collection enables the operating system to regain control of the recyclable memory blocks identified during the garbage detection phase.

The so-called garbage collection does not directly clear the data in this memory, but returns the right to use it to the operating system, so that the application does not occupy it.

what is garbage

1) When a variable is called and no longer needed, it is garbage.

2) When the variable name pointing to the variable address points to another address, the original variable memory address cannot be accessed, and the variable is also garbage at this time.

Python's garbage collection mechanism is mainly based on reference counting and periodic garbage collector to deal with circular references.

Reference counting

Principle explanation:

Reference counting is Python's primary garbage collection technology. Whenever a Python object is referenced, such as through an assignment operation, its reference count is incremented. When an object's reference is deleted or the object's scope is destroyed, its reference count is decremented. When the reference count reaches 0, Python's garbage collector releases the memory.

 for example

In Python, everything is an object, including integers, strings, lists, functions, etc. When you create an object in Python, say a = 10, a number object 10 is actually created in memory, and then there is a variable named a that refers to it. Python needs to remember how many variables this object has that refer to it. This is called reference counting. In this example, 10 has a reference count of 1.

If you create another variable that refers to the same object, such as b = a, then the reference count of this object 10 becomes 2 because it is referenced by two variables a and b. When you delete a reference (such as del a), the reference count is decremented by one. When the reference count becomes 0 (that is, no variables refer to this object), Python's garbage collection mechanism will automatically delete the object and release the memory.

Periodic garbage collector

Principle explanation:

Reference counting also has a major problem, and that is its inability to handle circular references. Circular references occur when two or more objects refer to each other, forming a cycle. This causes their reference count to never drop to 0, and therefore, the reference counting mechanism cannot free them. For example, if two objects a and b reference each other, even if no other object references them, they both have a reference count of 1, so they will not be reclaimed by Python's garbage collector.

 for example

If you have two objects, and they refer to each other, then even if you delete all external references to them, their reference count will never be 0, because they refer to each other. This is a circular reference, which causes a memory leak because these objects that refer to each other cannot be recycled.

To solve this problem, Python also has a periodic garbage collector. How it works is a bit more complicated, but in simple terms, it checks all objects periodically to find those with circular references, and then deletes them, even if their reference count is not 0. In this way, Python can recycle circularly referenced objects and prevent memory leaks.

po mode

Question: What is po mode?

PO pattern: Page Object is a page object design pattern, which is considered a relatively good design pattern. In this design pattern, functional classes (PageObjects) represent the logical relationship between each page.

It refers to converting a specific page into an object in a programming language, converting page characteristics into object properties, and converting page operations into object methods.

PO mode has the following advantages:

1. It can reduce the duplication of code writing.

2. The PO mode separates the positioning of page elements from the business operation process. Changes in interface elements do not require modification of the business logic code.

3. PO can improve the readability, high reusability and maintainability of the code.

Finally: The complete software testing video tutorial below has been compiled and uploaded. Friends who need it can get it by themselves [guaranteed 100% free]

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

picture

Guess you like

Origin blog.csdn.net/m0_67696270/article/details/132154981