Appium+Python implements a simple automated login test

This article mainly introduces the realization of simple automated login test implemented by Appium+Python. The sample code is introduced in the article in great detail. It has certain reference learning value for everyone's study or work. Friends who need it will follow the editor below. let's study together

foreword

If you want the mobile app to automatically log in, that is, let the app operate by itself. So in the script we need to operate the app control, then we need to get the information of the control. You can use uiautomatorviewer.bat in the ..\android-sdk-windows\tools directory to obtain control-related information

Get control related information

start uiautomatorviewer.bat

Open the mobile app, such as a calculator, connect it to the computer with USB, click the Android robot button Devices Screenshot button in the upper left corner of uiautomatorviewer to refresh the page

Positioning element: Move the mouse to the element to be positioned, such as the number 7. In the lower right corner, you can see the attributes corresponding to the element

Login script implementation


# coding=utf-8
__author__ = "Enoch"
# 这是一个app登录的测试
 
from appium import webdriver
from HTMLTestRunner import HTMLTestRunner
import unittest
import time
import warnings
 
 
class LoginTest(unittest.TestCase):
 
  def setUp(self):
    warnings.simplefilter("ignore", ResourceWarning)
    desired_caps = {
      'platformName': 'Android',
      'deviceName': 'SGEEGEHIQ8I7CIKF',
      'platformVersion': '6.0',
      'appPackage': 'com.mengtuiapp.mall',
      'appActivity': '.business.main.MainActivity'
    }
    self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
 
  def testCase(self):
    u"""登录"""
    driver = self.driver
    # time.sleep(2)
    driver.find_element_by_id("bottom_nav").click()
 
    time.sleep(2)
    driver.find_element_by_name('使用其他方式登录').click()
 
    driver.find_element_by_name('手机登录').click()
 
    driver.find_element_by_id("username").send_keys("13100010001")
 
    driver.find_element_by_name('获取验证码').send_keys("9876")
 
    driver.find_element_by_id("btn").click()
 
    driver.quit()
 
 
if __name__ == '__main__':
    print("----------执行---------- ")
    suite = unittest.TestSuite() # 构造测试集
    suite.addTest(LoginTest('testCase'))
    # 定义自动化报告目录
    filename = "F:\\report.html"
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(
        stream=fp,
        title=u'自动化测试报告',
        description=u'这是登录测试的简单报告'
     )
    runner.run(suite)
    fp.close()

Finally:  The complete software testing video learning tutorial below has been sorted out and uploaded, and friends can get it for free if they need it【保证100%免费】

insert image description here

 These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can help you too!

How to obtain interview documents:

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/129993244