Home Backend Development Python Tutorial A complete automated login test-2017-7-4

A complete automated login test-2017-7-4

Jul 04, 2017 pm 07:30 PM
test Log in automation

1

<span style="color: #577999; font-style: italic">#coding=utf-8<br><span style="color: #577999; font-style: italic"><br><span style="color: #161b99; font-style: italic">'''<br><span style="color: #161b99; font-style: italic">   Created on 2017-7-4<br><span style="color: #161b99; font-style: italic">   @auther:Qigege<br><span style="color: #161b99; font-style: italic">   project:<span style='color: #161b99; font-style: italic; font-family: "宋体"'>登录测试用例<span style="color: #161b99; font-style: italic"><br><span style="color: #161b99; font-style: italic">'''<br><span style="color: #161b99; font-style: italic"><br><span style="color: #4038e3">import unittest<br><span style="color: #4038e3">from selenium <span style="color: #4038e3">import webdriver<br><span style="color: #4038e3">from selenium.webdriver.firefox.firefox_binary <span style="color: #4038e3">import  FirefoxBinary<br><span style="color: #4038e3">import time<br><br><span style="color: #4038e3">class <span style="color: #dd2eee">LoginCase(unittest.TestCase):<br><span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">setUp(<span style="color: #94558d">self):<br>        binary=FirefoxBinary(<span style="color: #ef3142">'F:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">ff<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">MozillaFirefox50.1.0<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">firefox.exe')<br><span style="color: #94558d">self.driver=webdriver.Firefox(<span style="color: #660099">firefox_binary=binary)<br><span style="color: #94558d">self.url=<span style="color: #ef3142">'https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F'<br><span style="color: #ef3142"><br><span style="color: #ef3142">    <span style="color: #577999; font-style: italic">#<span style='color: #577999; font-style: italic; font-family: "宋体"'>定义登录的方法<br><span style='color: #577999; font-style: italic; font-family: "宋体"'>    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">login(<span style="color: #94558d">self,<span style="font-style: italic">username,<span style="font-style: italic">password):<br>        driver=<span style="color: #94558d">self.driver<br>        url=<span style="color: #94558d">self.url<br>        driver.get(url)<br>        driver.find_element_by_id(<span style="color: #ef3142">'input1').send_keys(<span style="font-style: italic">username)<br>        driver.find_element_by_id(<span style="color: #ef3142">'input2').send_keys(<span style="font-style: italic">password)<br>        driver.find_element_by_id(<span style="color: #ef3142">'signin').click()<br><br><span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>条件均正确暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic">    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_success(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username and password right'''<br><span style="color: #161b99; font-style: italic">        <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'******')<br>        time.sleep(<span style="color: #549937">2)<br>        link=<span style="color: #94558d">self.driver.find_element_by_link_text(<span style="color: #ef3142">'Qigege')<br><span style="color: #94558d">self.assertTrue(<span style="color: #ef3142">'Qigege' <span style="color: #4038e3">in link.text)<br><span style="color: #577999; font-style: italic">#<span style='color: #577999; font-style: italic; font-family: "宋体"'>截图<br><span style='color: #577999; font-style: italic; font-family: "宋体"'>        <span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">user_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>条件均正确<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold">    <span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>密码错误暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic">    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_pwd_error(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username right and password error'''<br><span style="color: #161b99; font-style: italic">        <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'123123')<br>        time.sleep(<span style="color: #549937">2)<br>        link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_btn')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名或密码错误<span style="color: #008080; font-weight: bold">',link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">err_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>密码错误<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold">    <span style="color: #577999; font-style: italic">#@unittest.skip(u'<span style='color: #577999; font-style: italic; font-family: "宋体"'>密码为空暂时跳过<span style="color: #577999; font-style: italic">')<br><span style="color: #577999; font-style: italic">    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_pwd_null(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username right and password null'''<br><span style="color: #161b99; font-style: italic">        <span style="color: #94558d">self.login(<span style="color: #ef3142">'Qigege',<span style="color: #ef3142">'')<br>        time.sleep(<span style="color: #549937">2)<br>        link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_input2')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>请输入密码<span style="color: #008080; font-weight: bold">' <span style="color: #4038e3">in link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">null_pwd.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>密码为空<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold">    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_user_err(<span style="color: #94558d">self):<br><span style="color: #161b99; font-style: italic">'''username error and password right'''<br><span style="color: #161b99; font-style: italic">        <span style="color: #94558d">self.login(<span style="color: #ef3142">'gege',<span style="color: #ef3142">'******')<br>        time.sleep(<span style="color: #549937">2)<br>        link=<span style="color: #94558d">self.driver.find_element_by_id(<span style="color: #ef3142">'tip_input2')<br><span style="color: #94558d">self.assertTrue(<span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名或密码错误<span style="color: #008080; font-weight: bold">',link.text)<br><span style="color: #94558d">self.driver.get_screenshot_as_file(<span style="color: #ef3142">'E:<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">py-sql<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">example<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">pro5_note<span style="color: #000080; font-weight: bold">\\<span style="color: #ef3142">err_user.jpg')<br><span style="color: #4038e3">print <span style="color: #008080; font-weight: bold">u'<span style='color: #008080; font-weight: bold; font-family: "宋体"'>用户名错误<span style="color: #008080; font-weight: bold">——<span style='color: #008080; font-weight: bold; font-family: "宋体"'>测试用例<span style="color: #008080; font-weight: bold">'<br><span style="color: #008080; font-weight: bold"><br><span style="color: #008080; font-weight: bold">    <span style="color: #4038e3">def <span style="color: #990000; font-weight: bold">test_login_user_null(<span style="color: #94558d">self):        '''username null and password right'''        self.login('','******')        link=self.driver.find_element_by_id('tip_input1')        self.assertTrue(u'请输入登录用户名' in link.text)        self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\null_user.jpg')        print u'用户名为空——测试用例'    def tearDown(self):        time.sleep(2)        print u'测试完毕!'        self.driver.quit()if __name__=='__main__':    unittest.main()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

Copy after login

The above is the detailed content of A complete automated login test-2017-7-4. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? Mar 19, 2024 pm 02:00 PM

When you log in to someone else's steam account on your computer, and that other person's account happens to have wallpaper software, steam will automatically download the wallpapers subscribed to the other person's account after switching back to your own account. Users can solve this problem by turning off steam cloud synchronization. What to do if wallpaperengine downloads other people's wallpapers after logging into another account 1. Log in to your own steam account, find cloud synchronization in settings, and turn off steam cloud synchronization. 2. Log in to someone else's Steam account you logged in before, open the Wallpaper Creative Workshop, find the subscription content, and then cancel all subscriptions. (In case you cannot find the wallpaper in the future, you can collect it first and then cancel the subscription) 3. Switch back to your own steam

How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? Mar 21, 2024 pm 09:41 PM

With the rapid development of social media, Xiaohongshu has become a popular platform for many young people to share their lives and explore new products. During use, sometimes users may encounter difficulties logging into previous accounts. This article will discuss in detail how to solve the problem of logging into the old account on Xiaohongshu, and how to deal with the possibility of losing the original account after changing the binding. 1. How to log in to Xiaohongshu’s previous account? 1. Retrieve password and log in. If you do not log in to Xiaohongshu for a long time, your account may be recycled by the system. In order to restore access rights, you can try to log in to your account again by retrieving your password. The operation steps are as follows: (1) Open the Xiaohongshu App or official website and click the &quot;Login&quot; button. (2) Select &quot;Retrieve Password&quot;. (3) Enter the mobile phone number you used when registering your account

What do you think of furmark? - How is furmark considered qualified? What do you think of furmark? - How is furmark considered qualified? Mar 19, 2024 am 09:25 AM

What do you think of furmark? 1. Set the &quot;Run Mode&quot; and &quot;Display Mode&quot; in the main interface, and also adjust the &quot;Test Mode&quot; and click the &quot;Start&quot; button. 2. After waiting for a while, you will see the test results, including various parameters of the graphics card. How is furmark qualified? 1. Use a furmark baking machine and check the results for about half an hour. It basically hovers around 85 degrees, with a peak value of 87 degrees and room temperature of 19 degrees. Large chassis, 5 chassis fan ports, two on the front, two on the top, and one on the rear, but only one fan is installed. All accessories are not overclocked. 2. Under normal circumstances, the normal temperature of the graphics card should be between &quot;30-85℃&quot;. 3. Even in summer when the ambient temperature is too high, the normal temperature is &quot;50-85℃

How to enter Baidu Netdisk web version? Baidu Netdisk web version login entrance How to enter Baidu Netdisk web version? Baidu Netdisk web version login entrance Mar 13, 2024 pm 04:58 PM

Baidu Netdisk can not only store various software resources, but also share them with others. It supports multi-terminal synchronization. If your computer does not have a client downloaded, you can choose to enter the web version. So how to log in to Baidu Netdisk web version? Let’s take a look at the detailed introduction. Baidu Netdisk web version login entrance: https://pan.baidu.com (copy the link to open in the browser) Software introduction 1. Sharing Provides file sharing function, users can organize files and share them with friends in need. 2. Cloud: It does not take up too much memory. Most files are saved in the cloud, effectively saving computer space. 3. Photo album: Supports the cloud photo album function, import photos to the cloud disk, and then organize them for everyone to view.​

How to log in if Xiaohongshu only remembers the account? I just remember how to retrieve my account? How to log in if Xiaohongshu only remembers the account? I just remember how to retrieve my account? Mar 23, 2024 pm 05:31 PM

Xiaohongshu has now been integrated into the daily lives of many people, and its rich content and convenient operation methods make users enjoy it. Sometimes, we may forget the account password. It is really annoying to only remember the account but not be able to log in. 1. How to log in if Xiaohongshu only remembers the account? When we forget our password, we can log in to Xiaohongshu through the verification code on our mobile phone. The specific operations are as follows: 1. Open the Xiaohongshu App or the web version of Xiaohongshu; 2. Click the &quot;Login&quot; button and select &quot;Account and Password Login&quot;; 3. Click the &quot;Forgot your password?&quot; button; 4. Enter your account number. Click &quot;Next&quot;; 5. The system will send a verification code to your mobile phone, enter the verification code and click &quot;OK&quot;; 6. Set a new password and confirm. You can also use a third-party account (such as

How to solve the common problem of Laravel login time invalidation How to solve the common problem of Laravel login time invalidation Mar 06, 2024 pm 09:24 PM

How to solve the common problem of Laravel login time expiration When using Laravel to develop web applications, login authentication is a very important function. However, sometimes if a user does not operate for a long time after logging in, the page may automatically log out or the authentication may fail. This problem is relatively common. The following will introduce how to solve this problem by setting the session time and provide specific code examples. 1. Set the session expiration time in Laravel, by default sessi

What should I do if I can't log in to my account on Google Chrome? Solution to why Google Chrome account cannot be logged in What should I do if I can't log in to my account on Google Chrome? Solution to why Google Chrome account cannot be logged in Mar 13, 2024 pm 02:10 PM

What should I do if I can’t log in to my account on Google Chrome? When many users use this software, certain functions require users to log in to their Google account before they can use it. However, they have tried many times but failed to log in successfully. Faced with this problem, many users do not know how to solve it, so In this issue, the editor is here to share the solution with you. I hope that the content of today’s software tutorial can be helpful to everyone. The solution is as follows: 1. Click on a browser on the desktop, and after opening it, you will see something like this. 2. If a login pops up at this time, click it. If you can't see it, click the upper right corner. 3. Click Login, then enter your account number. You do not need to enter the account after @, and click Next. 4. Enter the password. When you see this prompt, click Enable

Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Apr 22, 2024 pm 12:50 PM

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set

See all articles