30 python automated testing interview questions

Article Directory

1. What projects are suitable for automated testing?

Keywords: immutable, repeating, canonical
1) The task test is clear, and the requirements will not change frequently
2) The project cycle should be long enough
3) Automated test scripts can be reused, such as: more frequent regression tests
4) The development of the tested software system is relatively standardized, which can ensure the testability of the system
5) The interface of the software system is stable and there are few changes
6) The pressure of the project progress is not too great

2. What is PO mode?

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.
1) Generally speaking, each page is regarded as an object, and the page layer writes the positioning element method and page operation method
2) The use case layer calls the operation method from the page layer and writes it as a use case
3) The separation of positioning elements and scripts can be achieved
4) Mainly Used to achieve a separation of page operation and test logic

3. What are the encapsulation principles of PO mode?

1) To encapsulate the functions or services in the page, such as clicking a page element to enter a new page, you can encapsulate the method "enter a new page" for this service 2) Encapsulate details, only provide method names or interfaces externally, try not
to Expose the internals of the page
3) Do not use assertions in the encapsulated operation details, put the assertions in a separate module,
4) Click a button to open a new page, you can use the return method to jump, for example, return MainPage() means jump Go to the home page
5) You don’t need to encapsulate the behavior of the entire page, you can encapsulate whatever logic is used
6) An action may produce different results, for example, after clicking a button, it may succeed or fail, and encapsulate two results for the two results Methods: click_success and click_error

4. What are the functions of *args and **kwargs in Python?

They are all indeterminate length parameters, which solve the problem that the parameters are not fixed.
args is a non-keyword parameter, used for tuples; kwargs is a keyword parameter (dictionary),
that is to say, args represents any number of unnamed parameters, while kwags represents a keyword parameter with a corresponding relationship.
It should be noted that *args should be before **kwags when using, otherwise syntax errors will occur.

5. What is the garbage collection mechanism in Python?

The garbage collection mechanism (Garbage Collection), referred to as GC, is a mechanism that comes with the Python interpreter and is specially used for garbage collection.

When defining a variable, it will apply for memory space. When the variable is used up, the memory space occupied by the variable should also be released, and Python will be recycled by the GC 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 is to make the operating system regain control of the recyclable memory blocks identified in the garbage detection phase.

The so-called garbage collection does not directly clear the data in this memory, but re-hands the right to use it to the operating system, so that it will not be occupied by applications.

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.

6. How to locate hidden elements in selenium?

First of all, selenium cannot operate hidden elements (but can be located normally), the framework itself is designed like this, if you have to operate hidden elements, then use the js method to operate, selenium provides an entry to execute js scripts.
insert image description here
The hidden and displayed attributes of elements are mainly controlled by the type="hidden" and style="display: none;" attributes.

7. Close the difference between quit and close in the browser

To put it simply, both of them can realize the function of exiting the browser session.
close only closes the browser, while quit closes all browsers and also kills the driver process

8. Give an example of the exceptions you have encountered


ElementNotSelectableException: The element cannot be selected.
ElementNotVisibleException
: The element is not visible
.
Visible

9. How to deal with the alert pop-up window?

1) First use the switch_to_alert() method to switch to the alert pop-up box
2) You can use the text method to get the pop-up text information
3) Click the confirmation button through accept()
4) Click the cancel button through dismiss() to cancel the pop-up box
5) Pass text() gets the text of the popup window

10. How to deal with multiple windows in selenium?

Handle: the unique identifier of the window
1) First obtain the handle of the current window driver.current_window_handle
2) Then obtain all the window handles driver.window_handle
3) Loop to determine whether it is the window you want to operate, if so, you can operate the window; If not, use the driver.switch_to_window method to jump to a new window.

11. How to judge whether an element exists in selenium?

Selenium does not provide a native method to determine whether an element exists. Generally, we can determine by locating elements + exception capture.

insert image description here

12. What are the three types of waiting in automation? What are their characteristics?

1) Thread waiting (forced waiting) such as time.sleep(2): The thread is forced to sleep for 2 seconds, and after 2 seconds, the subsequent code is executed. It is recommended to use less.

2) implicitlyWait (implicit wait) will continue to search for elements within the specified time range until the element is found or timed out. The characteristic is that it must wait for the entire page to load.

3) WebDriverWait (explicit wait) is usually a function code customized by us. This code is used to wait for an element to be loaded before continuing to execute subsequent codes.

13. How to ensure the success rate of operating elements in selenium? In other words, how to ensure that the clicked element must be clickable?

1) Use WebDriverWait() to wait explicitly, wait for the element to be loaded, and then perform element operations.
2) Minimize unnecessary operations: If you can directly access the page, do not click to access it
3) Some pages take too long to load, you can consider interrupting the loading
4) Developers standardize their development habits, such as adding unique names to page elements , id, etc.

14. How to improve the execution speed of selenium script?

1) Use explicit waiting to reduce the use of mandatory waiting or implicit waiting.
2) Reduce unnecessary operation steps.
3) If the page loads too much content, set a timeout to interrupt the page loading.

15. The use case is often unstable during the running process, that is to say, it can pass this time, but it will not pass next time. How to improve the stability of the use case?

1) Try to add an explicit waiting time before the elements that often fail to be detected, and perform the following operations after the elements to be operated appear.
2) Use try to capture and handle exceptions
3) Try to use a dedicated test environment to avoid other types of tests being performed at the same time, causing interference to the data

16. What is the execution strategy for your automation use case?

The execution strategy of automated test cases depends on the purpose of automated testing. There are usually the following strategies:

1) The automated test case is used for monitoring. For this purpose, the automated test case can be set to be executed regularly. If it is executed every five minutes or an hour, just create a scheduled task on jenkins.

2) Use cases that have to fall back. Set the test case to trigger execution, and bind the automated test task to the developed build task on jenkins. When developers code on the simulation environment, automated test cases are triggered to execute.

3) Test cases that do not need to be executed frequently. Like full test cases, there is no need to return to execute all the time, and some non-main business lines do not need to return from time to time. This type of test case is executed manually. Create a task in jenkins and build it manually when it needs to be executed.

17. What is continuous integration?

Continuous integration is a software development practice in which team members integrate code into the mainline frequently, which means integrations can happen multiple times a day.

It has two main benefits:
1) Quickly find errors. Every time a little update is completed, it is integrated into the backbone, which can quickly find errors and locate errors more easily.
2) Prevent branches from greatly deviating from the trunk. If it is not integrated frequently and the backbone is constantly updated, it will make it more difficult to integrate in the future, or even difficult to integrate.
Purpose:
The purpose of continuous integration is to allow products to iterate quickly while maintaining high quality. Its core measure is that the code must pass automated tests before it is integrated into the backbone. As long as a single test case fails, it cannot be integrated.

18. Is it necessary to connect to the database for data verification during automated testing?

Required for interface testing, not required for UI automation

19. There are several commonly used positioning methods for elements, which are? Which is your favorite and why?

8 types, namely: id, name, class name, tag name, link text, partial link text, xpath, css

The most commonly used is xpath (or CssSelector)
because in many cases, the attributes of html tags are not standardized enough to locate through a single attribute. At this time, only xpath can be used to deduplicate and locate the only element

In fact, the fastest location is Id, because id is unique, but most developers do not set id.

20. How to locate the dynamically loaded elements on the page?

The dynamic change of attributes means that the element has no fixed attribute value, so it can only be located by relative position, such as the axis of xpath, to find the parent node or child node of the element, etc.

21. After clicking the link, will selenium automatically wait for the page to load?

Will not.
So sometimes, when selenium has not finished loading a page and requests page resources, it will falsely report that this element does not exist.
So first we should consider judging whether selenium has loaded this page. Then find the element through the function. (Use the display to wait, wait for the page to load before operating the element)

22. What is the principle of webdriver client?

After selenium starts, the driver acts as a server, communicates with the client and the browser, and the client sends requests to the driver according to the webdriver protocol. The driver parses the request, executes the corresponding operation on the browser, and returns the execution result to the client.

23. What is the protocol of webdriver?

The WebDriver Wire Protocol

24. Which webdriver protocol is used when starting the browser?

http protocol

25. How to choose an option with value=xx in the drop-down box?

1) The method provided in the select class: select_by_value ("xxx")
2) The syntax of xpath can also be located

26. What are the common variable parameter types and immutable parameter types in Python?

Immutable data types include: integers, floats, negative numbers, booleans, strings, tuples

Variable parameter types include: dictionary, list, collection

27. How to highlight elements after positioning them (for debugging purposes)?

Reset element attributes, add background and border to positioned elements

28. What is an assertion?

assert, to judge whether the test result is consistent with the expected result.
The purpose is to express and verify the expected result of the software developer - when the program executes to the position of the assertion, the corresponding assertion should be true. If the assertion is not true, the program will abort execution and give an error message.

29/ During the automated testing process, what problems did you encounter and how did you solve them?

1) Changing the page frequently requires modifying the code in the page object class
2) Occasional false positives in automated testing
3) Coverage of automated testing results: Jenkins creates folders based on time 4) Maintenance of automated testing codes is
troublesome5
) Automated testing for database comparison data

30. How to simulate the browser's forward, backward, and refresh operations

driver.navigate().forward() //forward
driver.navigate().back() //backward
driver.navigate0.efresh() //refresh

Guess you like

Origin blog.csdn.net/m0_37794269/article/details/127638480