Construction of mobile automation testing framework

Posted by deezerd on Sat, 30 Nov 2019 11:48:00 +0100

Some thoughts on the big framework:

  • What functions need to be implemented by the framework
  • In the early stage, data and business need to be separated to facilitate maintenance
  • The management of test case set shall be convenient, so as to re Run a single case in case of exception
  • Use case design needs to be as simple as possible and provide more common methods

 

 

  1. The current design framework is as follows:

  

  • CommonLibrary is used to store public libraries
  • Testcases repository is used to store test cases
  • TestData is used to store test data documents related to test cases
  • Testrun? XXX is the test result generated during the test, including test report and log
  • AutoRunTest.py is used to read the test case file to be executed from the case list and send the test report after the test
  • testcases.txt is used to store the use case table

2. There are some public methods in the public library, such as Appium operation, Excel file operation, mobile phone information configuration, test case information collection, test result folder production, test report writing, email sending, etc

The contents are as follows:

 

For example, Appiumserver is designed as follows:

#! /usr/bin/env python
#coding=utf-8
import os,time

def start_appiumServer(port11,port12,deviceuuid):
 
    os.system("cd C:\\Program Files (x86)\\Appium\\  && start node node_modules\\appium\\lib\\server\\main.js --address 127.0.0.1 --port "+port11+ " -bp "+port12+" -U "+deviceuuid)
    time.sleep(2)

def kill_appiumServer(port13):
    # Find the corresponding port's pid
    cmd_find = 'netstat -aon | findstr %s' % port13
    print(cmd_find)

    result = os.popen(cmd_find)
    text = result.read()
    pid = text[-5:-1]

    # Execute the pid
    cmd_kill = 'taskkill -f -pid %s' % pid
    print(cmd_kill)
    os.popen(cmd_kill)

if __name__ == '__main__':
    #start_appiumServer('4729','4728','BIBI5LEU6PRCDIIV')
    #start_appiumServer('4727','4724','75a2daf1')
    #time.sleep(10)
    kill_appiumServer(4729)
    kill_appiumServer(4727)

 

The structure of EmailUtils is as follows:

#! /usr/bin/env python
#coding=utf-8

import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE,formatdate
from datetime import datetime
import ResultFolder
from email.header import Header
import zipfile,os
import decode_pwd



def send_email(send_from,send_to,subject,text,files1,files2,server="smtp.163.com"):

    #assert(isinstance(send_to,list),"Send To email should be a list")

    msg = MIMEMultipart()
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Date'] = formatdate(localtime = True)
    msg['Subject'] = Header(subject, 'utf-8')
    my_password = "7A68656E676A696E6731313238"
    my_pass = decode_pwd.decode_pwd(my_password)

    msg.attach(MIMEText(text,'html'))

    with open(files1,"rb") as f:
        part1 = MIMEApplication(f.read())
        part1["Content-Type"] = 'application/octet-stream'
        part1["Content-Disposition"] = 'attachment; filename="TestResult.html"'
        msg.attach(part1)
		
    with open(files2,"rb") as g:
        part2 = MIMEApplication(g.read())
        part2["Content-Type"] = 'application/octet-stream'
        part2["Content-Disposition"] = 'attachment; filename="Test.log"'
        msg.attach(part2)
    smtp = smtplib.SMTP_SSL(server,465)
    smtp.login(send_from,my_pass)
    smtp.sendmail(send_from,send_to,msg.as_string())
    smtp.quit()

def zip_report(startdir,file_news):
    print startdir
    z = zipfile.ZipFile(file_news,'w',zipfile.ZIP_DEFLATED)
    for dirpath, dirnames, filenames in os.walk(startdir):
        fpath = dirpath.replace(startdir, '')  # This sentence is very important. If you don't replace it, start copying from the root directory
        fpath = fpath and fpath + os.sep or ''  # I am also a little depressed to realize the compression of the current folder and all the files contained
        for filename in filenames:
            z.write(os.path.join(dirpath, filename), fpath + filename)
    print ('Compression success')
    z.close()


def send_report():
    send_f = "xxxxx@163.com"
    send_t = "xxxxxx@163.com"
    subject = "Software test Report_"+ str(datetime.today())

    files1 = ResultFolder.GetRunDirectory()+"\\TestResult.html"

    print "zip log is start"
    zipdir = ResultFolder.GetRunDirectory()+"\\"
    file2_news = zipdir + 'TestLog.zip'
    zip_report(zipdir,file2_news)
    files2 = ResultFolder.GetRunDirectory() + "\\TestLog.zip"


    with open(files1,'r') as f:
        text = f.read()

    send_email(send_f,send_t,subject,text,files1,files2)

if __name__=='__main__':
    send_report()

  

Other modules are not listed one by one.

Topics: Python Excel Mobile