Hematemesis sorting, automated test scene processing (multi-scenario coverage) + solution


foreword

1. Add time wait
Why add wait?
In order to ensure the stability of the script, sometimes it is necessary to introduce a waiting time to wait for the page to load elements before performing operations

How to improve the success rate of script execution?
add wait time

What kind of waiting? What's the difference?
Mandatory waiting (fixed waiting): time.sleep() — must wait for a certain length of time before proceeding to the next operation
Disadvantages: not flexible enough, a lot of code duplication

Implicit waiting: implicitlyWait() ---- only used to locate elements, global waiting method; the code is written after the window is maximized
Advantages: the waiting time is smarter, if the element is not found, an exception will be thrown

Display waiting: WebDriverWait()---- wait for a certain condition to be established, if the condition is not established within the specified time, an exception will be thrown

WebDriverWait().until(条件)

What are the conditions?
There are various conditions in the expected_conditions module

2. Locate a group of elements
Find the common attributes of all elements for positioning

find_elements() --- 返回的是一个列表

3. Hierarchical positioning

driver.find_element_by_id(''***'').find_element_by_link_text(''***'')

4. Frame switching

Driver.swicth_to.frame()  # 切换到框架

Frame()
can only write the attribute value of the id or name of the iframe; write the recognition result of xpath

5. Multi-window processing

driver.switch_to.window()

6.
Hierarchical positioning of the drop-down menu;
use the attributes in the option element for positioning;
use the absolute path or relative path in xpath or css to select;
define a drop-down menu object, and use the index, text, and value attribute values ​​​​of the drop-down options make a choice;

7. File upload
Just use send_keys() to pass in the path of the file

8. Verification code
What is the function of the verification code?
For system safety, prevent machine operation

How to handle verification code?
In the test environment:
remove the verification code;
set the universal verification code;
process it through python code;
if there is only a verification code when logging in, you can use cookies to bypass it (you can also do it in an online environment);
go to the database or file to take out the verification code, and then judge;

9. Cookie processing
The role of cookies: store user information and user operations
The location where the cookie is saved: save it on the client side, and different browsers save it in different locations

Cookie is the storage format of time-sensitive
cookie information: key–value (key-value pair)
Open the homepage before logging in, check cookies -----> only one piece of data
, open the homepage after logging in, check cookies -----> only three The information of data
cookies is different, indicating that the cookie records the user's login information

10. The use of js
Js: javascript is a scripting language
, which is to write the js scripting language and then use python to execute it

There are three scenarios for executing js:

One is to execute js directly on the page—for example, to control the scroll bar of the browser; the
other is to execute js on a certain element that has been positioned;
modify the attribute value of the element through js;

The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Success is not achieved overnight, it must be through continuous hard work and struggle. Only by persevering and facing up to difficulties can we create our own brilliance. Don't give up, go forward bravely, only by making continuous progress can you achieve your dreams and career. Come on, you will succeed!

Only with unremitting efforts can we create our own brilliance. Don't give up the pursuit, because you can't predict what will happen in the next second. Every day is a new beginning, fight for your dreams!

No matter how far you are now, as long as you have dreams and goals, don't give up the struggle. Every step of hard work will bring you one step closer to success, keep at it, and you will find yourself running faster than others.

Guess you like

Origin blog.csdn.net/x2waiwai/article/details/131210022