In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what is the secondary encapsulation method of base python + selenium". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the secondary encapsulation method of basic python + selenium"?
First, create a subdirectory named Common under the root directory as public data, and create basepage.py and dir_config files under the Common directory. (as to what these two py files are going to do, it is mentioned later.)
First, let's open the dir_config file
If you look at the name, you can see clearly what this is going to do.
Logs_dir = os.path.join (base_dir, "OutPuts/logs")
(as for why it is written in this way, I am not going to introduce it. This article is aimed at having a foundation.)
In this line, it is the directory where the log is stored = the directory that my arrow points to, each of which is the same.
First, configure the directory path that you need to store, and configure it according to your own needs.
Next, we go to the basepage file.
First import the required modules and packages, as to why we use these modules, we will know later, hee
Create a class named BasePage
Write an initialization function plus a driver parameter. Self.driver = driver
This is waiting for the rewriting of the element operation, that is, the rewriting of WebdriverWait (). Until (expected_conditions.visibility_of_element_located ())
I also added a parameter doc, on which I wrote that the comment is module name _ page name _ operation name, so that if I report an error, I can clearly see which module, which page and which operation has gone wrong in the log, screenshot and report. There are other parameters I have comments, and every line of code I have comments, I will not talk about them one by one.
This is a rewrite of the lookup element
Why write a lookup element, please see below
This is a rewrite of the click operation, and I directly called the find, which is to find the element and click. Over and over again.
For example, send_keys () and so on.
And log is added before each operation.
For example, logging.info (f "{doc}: element: {locator} input: {text}")
If he got it correctly here, the log will show which module and which element to enter what content, write clearly, if wrong, on the contrary, I also typed the wrong log. (doc is which module, which page and which operation)
There are many other operations, all of which are the same routine. If you think my rewriting is good, you can follow my routine to write other operations.
Get elements, content operations, etc., I will not take screenshots one by one
For example, where something went wrong, there will be error logs, screenshots and so on under the specified path.
How much is the abortion operation in Zhengzhou http://mobile.chnk120.com/
And each error will bring doc to facilitate their own troubleshooting.
All right, let's do it. Let's use this framework.
First create a py file LoginPage for the landing page
Import BasePage and create a class to inherit BasePage
From PageLocators.LoginLocators.login_locators import LoginLocators as loc
This module is the location element where I store the login page
Since we have written the initialization function in BasePage, there is no need to write here.
Then we define a function of login with a username,password parameter, which is a formal parameter that represents the input user name and password
Define another doc
Directly use the secondary package we just rewrote.
First of all, we need to find the element of the user name input box and enter our user name in this element.
You can use input_text () directly.
Self.input_text (loc.name_text,username,doc)
Loc.name_text is the location expression and location element of the user name input box that we define, which I enclose in the form of meta-ancestor. Look at the picture above.
After the username is the parameter of the user name, wait for your test case to call the landing page operation, and then pass the user name data, I have every one with doc, so doc must be passed.
All operations are the same, and you can understand them all by understanding one.
Considering why the form of tuples can also be passed in, I'll give you a close-up here.
Look, I added this symbol in front of locator. This symbol means unpacking.
Self.driver.find_element (By.XPATH,'/ / * [contains (@ name, "username")]')
Actually, that's what it means.
Then I passed a Yuanzu quote directly to OK.
All right, then we'll write the test case using the pytest unit test framework, and then quote LoginPage
In this red box are the arguments of username and password, and this is the test data for calling login. It would be nice to understand it that way.
At this point, I believe you have a deeper understanding of "what is the secondary encapsulation method of base python + selenium". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.