The best summary of software testing interview questions, no one does not have this document

Summary of common interview questions

1. You have done testing and automated testing for several years, what is the principle of selenium?
I did five years of testing and one year of automated testing;

Selenium uses the http protocol to connect to the webdriver, and the client can be implemented using various programming languages ​​such as Java or Python;

2. What projects are suitable for automated testing?
Keywords: immutable, repeating, canonical

The first point is that demand changes cannot be too frequent;

The second point is that the project cycle should be long enough. If the automation code has not been written, the company will go bankrupt, and there is no need for automation

The third point is that scripts can be reused: in some typical scenarios, such as "smoke test, regression test", automated tests are often used;

The fourth point is whether the tested software is standardized: for example, whether there is a requirement document, a standardized interface document, whether there is a prototype diagram, and whether your interface design is relatively standardized;

Fifth point, manual testing cannot be completed; for example, a performance test cannot be done by a thousand hands at the same time, and the cost of automated testing is not particularly high

3. What is the difference between Python generators and iterators?
As an iterator must implement two specific methods "iter(), next()";

A generator is a licensed iterator that supports all iterative operations. In addition, the generator also implements some features that ordinary iterators do not have;

For example, it can interact with the generator through the send method; it can also be closed through the close method; it can even cause internal exceptions through the throw method;

4. Why use Mac to write code?
The superficial reason is that the Mac is easy to use and has a good appearance; the deep reason is that most of the current servers use the Linux system, and both the Mac system and the Linux system are actually developed based on the original Unix system;

And Mac can basically maintain the consistency of our development environment and online;

Why not use Linux?

Writing code with Linux is also a good choice, but the interface operation and entertainment functions of Linux are not particularly strong, while Mac has achieved a good balance;

5. How do you carry out automated testing work?
First, it can be sorted out according to the business characteristics of the product, and can be used as an automated function template;

Second, we will formulate an automated test plan based on the limited level and the current situation of personnel;

Third, we will select appropriate use cases from functional use cases to convert them into automation use cases;

The fourth is the selection of the framework, choosing the programming language or tools to realize it. Our team has a good ability to code, so we choose the Python language to realize it;

Fifth, is the script development of automated testing;

Sixth, develop an automated execution plan according to the project;

Seventh, it is the analysis of test reports, the report of automated test results, and follow-up maintenance in the later stage;

6. Please tell me what is a closure function?
The completed closure must contain the following three characteristics: a function must be nested in the function; the return value of the outer function is the function name of the inner function; the function of the memory nested function has a reference to a non-global variable;

Simply speaking, the closure function, the second one returns not only a simple function, but also stays in a closed scope;

7. Please introduce your automated testing framework?
Built an API interface automated testing framework in the previous company, using the unittest framework in Python combined with the requests module, using data-driven thinking (ddt) and layered design concepts to realize automated execution of test cases;

My framework is mainly divided into the following major modules:

Module 1: the cases (K color death) folder, the modules (registration, login, recharge) that are encapsulated according to the interface requirements, and the classes that save the test cases

Module 2: configs (Configus) folder, configuration files, common configuration in the storage project: file name, logger, database, url address

Module 3: datas (Detas): save the test case Excel document data;

Often the automation code of a test case is the same, but the data is different. The data and code will be separated and driven by ddt. This separation is data-driven thinking;

Put the data of a test case into Excel and database, and a piece of data represents a use case, which can simplify the code and facilitate maintenance

Module 4: libs (to Persia) folder, third-party library folder, ddt and HTML report;

ddt: Modify the ddt library, if the data is a dictionary, then get the value corresponding to the title in the dictionary and add it to the test case name; HTML report, use a more beautified and detailed report

Module 5: logs (Old Gus) folder, storing log files;

Module 6: reports (Rui Run times) folder, which stores the generated reports

Module 7: scripts (Siguai Perth) folder, which stores encapsulated classes and modules, and encapsulates general tool modules

constants: (Konsten dies) py file is the storage directory path file; use the os library to store the located file directory import os

handle_config.py: (Bean Bean. Confly) file encapsulates the read and write operations on the configuration file;

from configparser import ConfigParser Use the method of (Kang Fei Ge. Pai Er Shi) to read and write configuration files

handle_context.py: (Bean. Contex) py file is a parameterized package;

Use the re module and regular rules to realize parameterized search (translation: astringent) method search and sub (translation: Sabo) method replacement operation

handle_excel.py: (Bean. A Sail) py file is a package of Excel files;

Use the openpyxl module to process excel file pairs, read and write files, store test data (use case data) use case data); including: get all test cases, write the execution results in the specified line

Step 1. Open the excel file: use load_workbook (translation: mine is not available) to pass in the file name, the default is active to get the first form, otherwise get the specified form

Get the information of the table header, use the iter_rows (Aite wood shredded pork) method, nest the ancestors of the ancestors, and omit the minimum row number

The zip function splices the tuples of the table header with the tuples of each row of use cases, converts the dict into a dictionary, and adds it to the list one_list = []

handle_log.py: (bean. 啷) py file is to use the logging (啷 should) module to create a logger and record the log information in the project; import logging

1. Define the log collector, use the .getLogger method, the name of the collector case

2. To specify the log level of the log collector, use the .setLevel method in the logging object (Saite. Laiou)

3. Define the log output channel

Output to the console, using .StreamHandler (tap Muhandu) in logging (old root)

Output to a file, use the .FileHandler (event. Bean) method in logging (old root), (specify the file name, the default a is appended,)

4. To specify the log level of the log output channel, use the object.setLevel(Serter.Leo) method

5. Define the format of the log display, the Formatter (Fermet) function in logging (Old Root)

6. Docking, connect the log collector with the output channel, addHandler (press, bean) function in the collector

handle_mysql.py: (Bean. Mansekou) py file is MySQL database package;

Use the pymysql library to connect to the mysql database and package the database operations; mainly execute sql statements and perform data verification; import pymysql

import random (translation: soft wood), the random module in Python is used to generate random numbers

1. To establish a link, use connect (Keniket) in the pymysql library

2. Create a cursor cursor (roasted color)

3. Need to execute sql statement

4. Execute the sql statement, use the execute (Execute) in the cursor

5. Submit manually, using the commit in the link object (can be purchased once)

6. Get the execution result, use the fetchone in the cursor

7. Close the link and release the resource close (Kelou Division)

Close the cursor first cursor.close()

Then close the cursor object conn.close()

handle_request.py: (Bean. Ruikuaide) py file is the encapsulation of the requests request library;

Encapsulation using the requests (Ruikuaide) library to initiate requests to the interface; import requests

handle_user.py: (Bean. Responsible) The py file is

Use the above package: database operation, requests interface request package, configuration file package class, to create a user

run.py: entry file, collect and execute tests for

Automatically identify the method of loading test cases: discover (translation: Diskava) method

Load the test case first

Use the discover (Diskava) method in the defaultTestLoader in unittest (translation: drop fao's. Tester. Louze)

The first one, using . to represent the path where the current py file is located, automatically loads the py file module starting with test

The second is to load with an absolute path and use r for transcoding

Execution use case

1. Need to create an actuator object, use the TextTestRunner in unittest (translation: Tester. Tester. Soft there)

one_runner = unittest.TextTestRunner()

2. Run the suite

one_runner.run(one_suite)

Able to use the web automation test framework, adopt PO mode and keyword-driven thinking, use the pytest framework in Python combined with selenium module and allure plug-in to realize the automatic execution of test cases

8. What is the difference between pytest and unittest?
First of all, unittest is the official library of pytest, which has better compatibility and stability. When pytest is installed, there may be compatibility issues with the Python version;

In the writing of use cases, in unittest, use cases are written in the form of classes, and must inherit from this testcase;

In pytest, functions and classes are supported, and pytest has the file conftest.py to support global shared front and back;

In terms of use case collection, in unittest, use testloader and testsuite to actively collect and load use cases; in pytest, use cases can be automatically identified;

In terms of use case classification and screening, it is more troublesome to filter and process existing use cases in unittest; in pytest, use case screening can be easily realized by marking;

On the mechanism of running failure, in unittest, the official library does not provide a failure restart mechanism; in pytest, there is a built-in failure re-run mechanism;

In the running process, there are no supported plug-ins in unittest; there are more than 700 plug-ins in pytest, and the supported plug-ins are very rich;

9. What is a list comprehension?
Derivation is an advanced usage for generating data in Python. Python not only has list derivation, but also dictionary derivation, set derivation, and generator expressions;

Its syntax is the same, and it is a shorthand way to create data through a for loop;

10. What is PO mode?
PO mode: Full name: Page Object Model (translation: match only. Aobo pick t. Maodou) referred to as POM, called page object, for pages and UI interfaces;

The idea of ​​PO mainly comes from an article published by Marktin Flowwer in 2004. At first, he was not called PO, but window driver. Later, selenium followed this idea, so it was changed to PO;

Main purpose: to convert a specific page into an object in a programming language, page characteristics into object attributes, and page operations into object methods;

In automated testing, it is mainly used to separate page operations and test logic;

11. What is the most familiar selenium operation?
Basically, the following major types of operations provided by selenium can be used flexibly, for example: eight major element positioning methods, three major waiting methods, user clicks, input and other common operations,

There are also window switching and iframe switching operations, such as actionchains file uploads, JS operations and other complicated operations;

If selenium has not provided an on-site encapsulation method, it will refer to the webdriver standard provided by the W3C organization to capture it by itself;

12. Is there any other way to click on the login button in selenium?
There are also two ways: for example, to use a physical keyboard to operate and issue a carriage return command; then, if the login button is in a form, you can also locate the user input box and after the input, Submit directly in 3D

13. What are the encapsulation principles of PO mode?
Selenium provides us with six principles on the official wiki, which can be understood in the actual testing process:

The first principle is that the public method represents a service provided by the page. For example, we can encapsulate the login method into a logo method, the search method into a facility method, and the registration operation into a register method;

The second principle is to try not to expose the inside of the page; for example, an HTML page also has a page structure;

The third principle is that assertions are generally not made in POs, and page logic and test logic will be separated

The fourth principle is that the methods in PO generally return self or other Page Objects, which can also be an element attribute

The fifth principle is that you don’t need to encapsulate the behavior of the entire page in the entire PO, you can encapsulate whatever logic is used

The sixth principle is that for unified operations, if there are different results, they can be expressed in different ways. For example, there is a jump when the login is successful, and an error is reported when the login fails.

If there is another authorization situation for login, it can be encapsulated into three separate methods: login success, login error, login invalid

14. Have you ever heard of the small integer pool in Python?
The small integer pool means that when the Python program is running, the Python interpreter will automatically create an integer object between negative 5 and 256 and save it in the cache, which is what we call the small integer pool;

When these integers are copied to variables in the program, the Python interpreter will continue to reallocate memory to create this object, but directly reference the object in the created cache;

The original intention of the design of the small integer pool is to optimize the operating efficiency of the program. When the same integer is needed, it can be used directly from this integer pool, which can avoid frequent creation and destruction of this object, improve efficiency and save memory;

15. What is the difference between XPath and CSS selectors?
The writing method of CSS will be simpler, and the xpath will be relatively complicated. In mainstream browsers, the efficiency of CSS parsing is higher, and the search speed will be faster;

XPath supports more functions, and the flexible operation method will be more powerful. For complex element positioning, xpath will be more concise;

CSS does not support text positioning; XPath supports text positioning;

16. How do you deal with the interfaces that require authentication?
First, confirm what method the interface uses for authentication, whether it is cookie_session or token;

If it is the way of cookie_session, then you can directly use the session class in the requests module to create an object to send the request directly, and it will automatically record the cookie information;

If it is a token, first analyze how the token is returned, and then extract the value of the corresponding token, which needs to be passed in according to the requirements when sending the request;

17. What is the common waiting method in UI automation?
There are three main ways to wait in UI automation testing:

The first one, forced waiting, is generally not used by us; it is mainly used in places where different systems interact;

The second is implicit waiting: this kind of waiting is smarter, it can be configured globally, but intelligence is used for element positioning;

The third, display waiting: it is a more flexible waiting method in selenium; its realization principle is actually to try the operation that needs to be performed through the while loop;

19. What is the difference between find_element() and find_elements()?
find_element() : Returns the first element found, if not found, an error will be reported directly;

find_elements() : will return all eligible elements and put them in a list; if not found, no error will be reported, and an empty list will be returned;

20. What is XPATH?
Xpath is an XML Path Language (XML Path Language), which can be used to query the location of elements in each web page. During the automated testing process, we can accurately locate the elements of web pages and APP pages

Then in the crawler field, the page structure can be flexibly parsed

21. When the request module sends a request, how to pass parameters?
First of all, you need to confirm what type of request parameter the interface is. If the interface needs query string parameters, then use params to check; if the interface needs json-type parameters, then use json to check directly;

If it is the case of uploading files, it can be passed through the parameters of files;

If it is a form type, you can use data to pass, and data is used to pass form type parameters by default;

Then when using data to pass parameters, you can also specify the type of the request parameter through the content type in the request header

22. How does selenium automate file uploads?
If it is a file upload of an input element, it can be passed through the send_keys method in selenium, but this method has relatively large limitations. If you encounter a component called through js, there will be some problems;

At this time, it is necessary to complete the upload operation through some ways of interacting with the system, such as through third-party libraries such as autoit, pywinauto or pyautogui

23. How many ways to reverse the list?
The first one is that it can be reversed by slicing in reverse order, and then the step size is -1;

The second way is through the list. The list has a method called reverse (translation: Ruiwaier 4), which can realize the reversal;

24. What is the difference between class methods, instance methods, and static methods in Python?
The class method is the method of the class. When defining it, you need to add a @classmethod to modify it. The formal parameter is cls; both classes and instances can be called;

The instance method is an instance object method, only the instance object can be called, the class cannot be called, and the formal parameter is self refers to the object itself;

A static method is an arbitrary function, but it just happens to be placed in this class. It needs to be modified by adding a @staticmethod above it, which can be called directly by an object; the static method has nothing to do with this class;

25. What are decorators in Python?
Decorator, also called decorator, is a high-level syntax in Python. Decorators can be implemented by classes or functions. Usually, the @ symbol is used to represent a decorator;

Function: It is used to extend the function of casting a function or class

26. What is the difference between deep copy and shallow copy in Python?
Deep and shallow copying is usually discussed in the case of data nesting. When the nested data is variable type data, we must consider this deep and shallow copying when copying the data;

Shallow copy, for example, list nested list, the copy method that comes with the list is shallow copy;

When calling the copy method to copy a list, only this list will be copied, and other data referenced in the list (such as nested lists) will not be copied, but are directly referenced;

Due to the incomplete copying of shallow copy, when the data referenced by the original list is sent and changed, the copied data will also be affected

To make a deep copy, you need to use the deepcopy method in the copy module. When calling the deepcopy method to copy a list, not only will the list be copied, but other data referenced in the list (such as nested lists) will also be copied;

27. What is the PEP8 specification?
The PEP8 specification is also called the Python8 Enhancement Proposal, which is a guideline mainly aimed at the writing style of Python code;

For example: first in a module, the functions or classes in the module are separated by two lines; then the methods in the class are separated by one line; the indentation of the code line is usually represented by a tab key and four spaces;

Then the specification of one line of code PEP8 points out that the maximum should be 79 characters;

There are still many requirements for this specification, so I will not give examples one by one;

28. What is the overloading mechanism of Python functions?
Function overloading is mainly to solve two problems: the first is the variable parameter type, and the second is the number of variable parameters;

In Python, the parameters do not need to declare the type, and the function can accept any type of parameter; if the function of the function is the same, a function can handle it;

In Python, one * and two ** are used to handle the number of variable parameters; so in Python, he does not need to deal with function overloading;

29. What are the common variable parameter types and immutable parameter types in Python?
Immutable data types include: Integer, Float, Negative, Boolean, String

Variable parameter types include: dictionary, list, set, tuple

30. At what stage does your project involve interface automation testing?
First of all, my project is a brand new project, I am responsible for interface testing, and the other five people are responsible for functional testing; because it is a new project, I started to get involved in interface automation during the project development stage;

We wrote automation use cases. We used the yapi platform to manage the interface, which is equivalent to providing interface documents. Due to the relatively early intervention time, hundreds of bugs were found in automation during this process;

It saves a lot of time for the later functional testers, and at the same time can ensure that they can keep up with the pace of frequent online;

31. Have you ever learned about the intern mechanism in Python?
When running a Python program, a blank memory space will be specially allocated to store a string composed of numbers, letters, and underscores, that is, a string composed of pure words and characters.

This blank memory is called the string resident pool, also known as the large integer pool;

The so-called intern mechanism means that when a new string is created during the running of the program, first, according to the string, it is checked in the resident pool whether the string has been created in the resident pool;

If there is any, it will be used directly, if not, it will be recreated; if it is a pure word character after creation, it will be added to the resident pool. Such a mechanism can avoid frequent creation and destruction ;

This object can improve the operating efficiency of our program;

32. What is the role of *args and **kwargs in Python?
They are all indefinite length, which can solve the problem that the parameters in the function are not fixed. *args can convert positional parameters into tuples; **kwargs can convert keyword parameters into dictionaries;

33. Process, thread, collaboration, how do you understand it?
Process is the basic unit of operating system resource allocation; thread is the basic unit of operating system scheduling; collaboration is also called micro-thread, and collaboration exists in thread, which is an executable unit smaller than thread;

Processes and threads can be scheduled according to the operating system, and may be executed concurrently or in parallel; collaboration is in a thread, only concurrent but not parallel

34. What are the disadvantages of Python's multithreading?
According to the official Python documentation, due to the existence of the global interpreter lock of the Cpython interpreter, only one thread can execute multiple threads at the same time.

It means that multithreading in Python can only be executed concurrently, and there is no way to achieve true parallelism; that is, the resources of multi-core CPUs cannot be utilized

35. How does Python operate the MySQL database?
There are several libraries that can be used: pymysql, or mysql_clinet can be connected; after the cursor object is established, the SQL statement can be directly executed

36. What is the naming ancestor in Python?
The named tuple is a class called namedtuple provided by Python, which can be imported from the collection package. The named tuple inherits from the tuple class, so it has the characteristics of a tuple.

At the same time, it can be obtained by accessing attributes, the readability of tuple elements is greatly improved, and it can also be converted into a type like a dictionary very conveniently;

37. How many ways are there to define the parameters of a function?
Required parameters, default parameters, variable length parameters

38. How many forms are there to define methods in a class?
instance method, static method, class method

Class methods and instance methods are related to classes or instances, and their parameters are always an instance or class

But a static method is an ordinary function, but we just threw him into this class, and its parameters did not say that it must be a class or who;

39. Several concepts and components of the unittest framework?
There are five concepts in total:

TestCase: It is used to write test cases. All test cases we write need to inherit the testcase class;

TestSuite: It is a container for loading test cases, that is, a test suite.

TesttLoader: It is used to collect test cases and load them into the test suite;

TestTestRunner: It is used to run test cases and generate reports in text form; we can replace it with HtmlTestRunner to generate reports in HTML format;

fixture: Yes, it is a fixture, use cases or pre- and post-work of use cases can be done in this

40. Do you know the magic method in Python?
I have learned that the built-in double underscore and end methods in the Python class are called magic functions, which divide under certain circumstances;

For example: class initialization init, which is automatically called when an object is created, is used to initialize the object;

Many features in Python are implemented through magic methods.

41. How to define anonymous functions in Python?
Defining an anonymous function in Python is very simple, just define it through a lambda expression;

The basic syntax of a lambda expression is: lambda space and then add the parameters of the function, followed by the return value of the function after the colon;

42. What is the difference between the queue module queue and the process queue queue in Python?
The Queue in the queue module can only communicate in the same process, and can only realize multi-thread data interaction, but cannot realize multi-process data interaction;

Then the Queue in the process module can be used across processes, enabling multi-process data interaction.

43. What is the difference between a synchronous request and an asynchronous request?
Synchronous request means that in a thread, after you initiate a request, you cannot initiate the next request until you receive the returned result;

Asynchronous request means that in the same thread, after you initiate a request, you can continue to initiate other requests during the period of time waiting for the return result

44. Why is the with operation file not manually closed in Python? What is the principle?
The with keyword in Python, which is used to start the context manager of an object;

His principle is: when we use with to open a file through open, it will trigger the context manager of the file object, and then when the code in with finishes running, it will automatically call the exit method of the context manager;

In this method, he will call close to close the file, so we don't need to close the file manually;

45. What is the garbage collection mechanism in Python?
Our commonly used Python interpreter CPython mainly uses three garbage collection mechanisms to complete the recovery of this invalid data and the release of memory, namely: reference counting, mark clearing and generational collection

The strategy of garbage collection is based on this reference count, and then mark cleanup and generational collection are only auxiliary means;

46. ​​What is the difference between curl and wget?
curl is a more powerful network access tool, with a very powerful parameter passing system, not only supports the HTTP protocol, but also many protocols like FTP;

If you want to simply send a request, you can use wget; if you want to test the network full-time, it will be more at ease to use curl

47. What is encoding and decoding?
Encoding is the process of converting from one form or format to another through certain rules; decoding is the opposite;

For example, for strings in programming, we often need to encode them into binary format through UTF-8 format; then the decoding process is to convert this binary format into a string format;

Software Testing Interview Documentation

 

The entire document has a total of 216 pages . It is definitely unrealistic to show you all of them. In order not to affect your reading experience, only part of the content is shown. I hope you will bear with me. I hope it can help you review before the interview and find A good job, and it also saves everyone the time of searching for information on the Internet to learn! 

 

Guess you like

Origin blog.csdn.net/HUA1211/article/details/130488056