Home > Article > Backend Development > Python automation testing interview FAQs and answers
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
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
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
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.
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.
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.
The attribute hiding and displaying of elements is mainly controlled by the type="hidden" and style="display: none;" attributes.
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
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
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()
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.
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.
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.
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.
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.
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
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.
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.
Required for interface testing, not required for UI automation
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.
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.
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)
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.
The WebDriver Wire Protocol
http protocol
1) The method provided in the select class: select_by_value ("xxx")
2) The syntax of xpath can also be located at
Immutable data types include: integers, floating point numbers, negative numbers, Boolean values, strings, tuples
Variable parameter types include: dictionaries, lists, sets
Reset element attributes, add background and border to positioned elements
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.
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
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!