python + Appium automation: BSTestRunner execute test cases, test report generation

The use case is defined as start, end, writing the common module, the script is as follows:

myunit.py

import unittest
from TB_test.common.TB_caps import appium_desired
import logging

class startend(unittest.TestCase):

    def setUp(self):
        logging.info("=====setUp=====")
        self.driver=appium_desired()

    def tearDown(self):
        logging.info("=====tearDown=====")
        self.driver.quit()

  

Test Case:

test_login.py

the unittest Import 
from TB_test.common.myunit Import startend 
from the LoginView TB_test.businessView.loginView Import 
Import the logging, Time 

class testlogin (startend): 
    # the address registration information file configuration 
    CSV_File = '.. / Data / account_data.csv' 
    DEF test_login_right (Self ): 
        logging.info ( "================ test_login_right ================") 
        L = the LoginView (self.driver) 
# call profile Data = l.get_csv_data (self.csv_file,. 1) l.login_action (Data [ 0], Data [. 1]) self.assertTrue (l.cheak_login ()) DEF test_login_error (Self): logging.info ( "================ test_login_error ================") L = the LoginView (self.driver)
# call profile data=l.get_csv_data(self.csv_file,2) l.login_action(data[0],data[1]) self.assertTrue(l.cheak_login()) time.sleep(5) if __name__ == '__main__': unittest.main()

Implementation of test cases:

runcase.py

the unittest Import 
from BSTestRunner Import BSTestRunner 
Import Time, the logging 

# use case path, the report stored path 
test_dir = '../testcase' 
report_dir = '../reports' 
# loading test 
discover = unittest.defaultTestLoader.discover (test_dir, pattern = " _ * Test. Py ") 
Print (Discover) 

# named report 
now The time.strftime = ("% D% Y-% M-% H_% of M_% S ") 
REPORT_NAME = report_dir + '/' + + now 'testreport.html' 

# run the test case, generate reports 

with Open (REPORT_NAME, "WB") AS F: 
    Runner = BSTestRunner (Stream = F, title = U 'automated test reports, test results are as follows:', description = u 'implementation Example used:') 
    logging.info ( "Start runcase ====== ======") 
    runner.run (the Discover)

After completion of the execution report addresses with the embodiment can be seized, note introduced BSTestRunner module need to download in advance, is placed in the path to python-lib.

 

Guess you like

Origin www.cnblogs.com/bugbreak/p/12517338.html