In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Python automation data-driven example analysis, with certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.
preface
Data-driven is an idea that separates data from code. For example, when crawling, we need to paginate and crawl data. We often parameterize the number of pages and put them in the for loop range. If there is no range, this method that comes with a number sequence can be used. Do we have to manually add them one by one?
There are a lot of such examples in the real scene. For example, when I wrote before crawling the rent situation of various regions in Shanghai, when traversing the regions, in order to be lazy, I directly put the pinyin full names of these regions in the list and combine them into links to the houses in each region. Finally, the article was finished, with feedback from readers, missing statistics from Xuhui District. This small amount of data has been flawed, and it is conceivable that for a large amount of data, how to ensure the integrity and accuracy of the data? We need to separate the two and store the data exclusively in specific files (such as Excel files).
Take a small chestnut: login process, in the test, in addition to the test login success scenario, we often need to test various login abnormal scenarios.
Write a few common examples as follows:
For example, if the above five cases are written, the data and scripts are not separated, and we need to write five automated test scripts.
In the five cases, the scripts are basically the same, except that the data entered in the input box is different.
data separation
We can store the data in Excel, and we can execute multiple pieces of data in one script by reading the data in Excel repeatedly.
We first encapsulate a class that operates Excel files. We need to install the import package openpyxl first.
We can use this library to do the following functions: read table data, save execution results.
We first write an initialization method under the class to open the Excel file. The constructor is used to call the constructor immediately after the class is instantiated.
Read table data
Then we write a method to read Excel data, return the data list after reading the data, so that we can call to get the corresponding data later, because the first column data is the serial number, so directly return the data after the second column.
Save execution results
After comparing the actual result with the expected result, we need to mark the execution result as pass or fail, and we need to save the result and save it to the corresponding cell.
Let's look at our case format:
In this case, we do not have to write 5 scripts, call Excel file data, cycle execution case, not only logical clarity, but also convenient for later maintenance.
In this way, after the test data and script are separated, different test data can be saved in different Excel files.
Thank you for reading this article carefully. I hope that the article "Python Automation Data-driven Sample Analysis" shared by Xiaobian will help everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.