Home > Backend Development > Python Tutorial > Python automation testing interview FAQs and answers

Python automation testing interview FAQs and answers

王林
Release: 2023-04-27 15:31:07
forward
2309 people have browsed it

1. What projects are suitable for automated testing?

Keywords: unchanged, repetitive, standardized

1) The task test is clear, and the requirements will not change frequently

2) The project cycle must be long enough

3) Automated test scripts can be reused, such as: more frequent regression testing

4) The development of the software system under test is relatively standardized and can ensure the testability of the system

5 ) The software system interface is stable and changes little

6) The project progress pressure is not too high

2. What is the PO model?

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 positioning element method and page operation method are written at the page layer

2) The use case layer calls the operation method from the page layer and is written as a use case

3) It can separate positioning elements and scripts

4) It is mainly used to realize the separation of page operation and test logic

3. The encapsulation principles of PO mode are: Which ones?

1) To encapsulate the functions or services in the page, for example, if you click on the page element to enter a new page, you can encapsulate the method "Enter a new page" for this service

2) Encapsulation Details, only provide method names or interfaces to the outside world, try not to expose the internals of the page

3) Do not use assertions in encapsulated operation details, put assertions in separate modules,

4) Clicking a button will open a new page. You can use the return method to jump. For example, return MainPage() means jumping to the homepage

5) The entire PO. You don’t need to encapsulate the behavior of the entire page. You can use whatever logic you want. What to encapsulate

6) An action may produce different results. For example, after clicking a button, it may succeed or fail. Encapsulate two methods for the two results: click_success and click_error

4. Python What is the role of *args and **kwargs?

are all variable-length parameters, which solves the problem of non-fixed parameters.

args are non-keyword parameters, used for tuples; kwargs are keyword parameters (dictionaries)

That is to say, args represents any multiple unnamed parameters, but kwags represents a corresponding relationship Keyword arguments.

When using, please note that *args must be before **kwags, otherwise a syntax error will occur.

5. What is the garbage collection mechanism in Python?

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

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 recycle it 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 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 is 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 it can be positioned normally). The framework itself is designed like this. If you have to operate hidden elements, then use js method to operate. Selenium provides a The entrance can execute js scripts.

Python automation testing interview FAQs and answers

The attribute hiding and displaying of elements is mainly controlled by the type="hidden" and style="display: none;" attributes.

7. The difference between quit and close in closing the browser

Simply speaking, both can realize the function of exiting the browser session.

close will only close the browser, while quit will also kill the driver process when closing all browsers

8. Give examples of exceptions you have encountered

  • ElementNotSelectableException: The element cannot be selected.

  • ElementNotVisibleException: The element is not visible.

  • NoSuchAttributeException: No such attribute exception

  • NoSuchElementException: No such element exception

  • NoSuchFrameException: No such frame exception

  • TimeoutException: Timeout exception

  • Element not visible at this point: The element is not visible at the current point

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 through accept() Confirm button

4) Click the cancel button through dismiss() to cancel the pop-up box

5) Get the text of the pop-up window through text()

10. How to do it in selenium Dealing with multiple windows?

Handle: the unique identifier of the window

1) First get the handle of the current window driver.current_window_handle

2) Then get all the window handles driver.window_handle

3) Loop to determine whether it is the window you want to operate. If it is, you can operate the window; if not, use the driver.switch_to_window method to jump to a new window.

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

Selenium does not provide a native method to determine whether an element exists. Generally, we can determine by positioning the element and catching the exception.

Python automation testing interview FAQs and answers

#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. 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.

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 and wait for the element to be loaded before performing element operations.

2) Try to reduce unnecessary operations: if you can access the page directly, do not access it through click operations

3) Some pages take too long to load, you can consider interrupting the loading

4) Developers standardize development habits, such as adding unique names, ids, etc. to page elements.

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

1) Use explicit waiting to reduce the use of forced waiting or implicit waiting.

2) Reduce unnecessary steps.

3) If the page loads too much content, set a timeout and interrupt the page loading.

15. Use cases often become unstable during operation. That is to say, if they can pass this time, they will not pass next time. How to improve the stability of use cases?

1) Try to add an explicit waiting time before the elements that frequently fail to be detected, and wait until the element to be operated appears before performing the following operations.

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 and causing interference to the data

16. Your What is the execution strategy for automation use cases?

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

1) Automated test cases are used for monitoring. For this purpose, you can Set the automated test case 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 must be returned. Set the test case to trigger execution, and bind the automated test task to the development build task on Jenkins. When developers code in the simulation environment, automated test cases are triggered and executed.

3) Test cases that do not need to be executed frequently. Like full test cases, there is no need to return to execution 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 development members frequently integrate code into the trunk, which means multiple integrations may occur every day.

It has two main benefits:

1) Quickly detect errors. Every time an update is completed, it is integrated into the backbone. Errors can be quickly discovered and it is easier to locate errors.

2) Prevent branches from deviating significantly from the trunk. If integration is not frequent and the backbone is constantly being updated, it will become more difficult or even difficult to integrate in the future.

Purpose:

The purpose of continuous integration is to allow products to iterate quickly while maintaining high quality. Its core measure is that before the code is integrated into the trunk, it must pass automated testing. As long as one 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. What are several commonly used positioning methods for elements? Which one is your favorite and why?

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

The one I use most is xpath (or CssSelector)

Because in many cases, the attributes of html tags are not standardized enough and cannot be positioned through a single attribute. At this time, xpath can only be used to remove duplicates and locate the only element

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

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

Dynamic changes in attributes mean that the element does not have a fixed attribute value, so it can only be positioned through relative positioning, such as through 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 be loaded?

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 finished loading this page. Secondly, find the element through the function. (Use display wait to wait for the page to load before operating elements)

22. What is the principle of webdriver client?

After selenium is started, the driver acts as a server, communicating with the client and browser. The client sends requests to the driver according to the webdriver protocol. The driver parses the request, performs corresponding operations on the browser, and returns the execution results 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 select an option with value=xx in a drop-down box?

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

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

Immutable data types include: integers, floating point numbers, negative numbers, Boolean values, strings, tuples

Variable parameter types include: dictionaries, lists, sets

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 determine whether the test results are consistent with the expected results

The purpose is to express and verify the results expected by software developers--when the program executes to the assertion position, the corresponding assertion should is true. If the assertion is not true, the program will terminate execution and give an error message.

29/What problems did you encounter during the automated testing process and how did you solve them?

1) Frequently change pages and often modify the code in the page object class

2) Automated testing occasionally produces false positives

3) Automated testing results are overwritten Situation: Jenkins creates folders based on time

4) Automated test code maintenance is troublesome

5) Automated testing performs database comparison data

30. How to simulate browsers Forward, backward, refresh operations

  • driver. navigate().forward() //Forward

  • driver.navigate().back( ) //Back

  • driver.navigate0.efresh() //Refresh

The above is the detailed content of Python automation testing interview FAQs and answers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template