-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunFromSuite.py
More file actions
61 lines (50 loc) · 2.36 KB
/
RunFromSuite.py
File metadata and controls
61 lines (50 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
from LoginTest.Test_for_Login import GmailLoginTest
import os
from HTMLTestRunner import HTMLTestRunner
import BeautifulReport
#Create a test suite
suite = unittest.TestSuite()
'''There are five ways to add test cases.'''
# method 1 to add test cases, one by one
# suite.addTest(GmailLoginTest('test_6'))
# suite.addTest(GmailLoginTest('test_7'))
# method 2 to add test case, from list
# cases = [GmailLoginTest('test_6'), GmailLoginTest('test_7')]
# suite.addTests(cases)
# method 3 to add test cases, all cases in both Test_for_Login.py & Test_for_Demo.py
# test_dir = './LoginTest'
# discover = unittest.defaultTestLoader.discover(test_dir, pattern='Test_for*py')
# method 4 to add test cases. all cases in GmailLoginTest class
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(GmailLoginTest))
# method 5 to add test cases. Do not need to import.
# suite.addTest(unittest.TestLoader().loadTestsFromName('LoginTest.Test_for_Login.GmailLoginTest'))
# Run cases in suite
if __name__ == '__main__':
# Run cases using unittest in python IDE
# runner = unittest.TextTestRunner()
# runner.run(suite)
# runner.run(discover)
'''Generate test reports using multiple methods
-----------------------------------------------'''
'''Using HTMLTestRunner to generate report'''
# Define report's name and title
report_name = "Test Report.html"
report_path = './Report/'
report_file = report_path + report_name
report_title = "Test Result for login module"
report_description = "Test result for login module with both valid and invalid input, also covering error guessing input"
# Create report folder if it does not exist.
if not os.path.exists(report_path):
os.mkdir(report_path)
else:
pass
# run cases from HTMLRunner and generate report
with open(report_file, 'w') as report:
runner = HTMLTestRunner.HTMLTestRunner(stream=report, title=report_title, description=report_description)
runner.run(suite)
'''Generate test report using Unittest'''
# with open('Report/reportUnitTest.txt', 'w+') as report:
# unittest.TextTestRunner(stream= report, verbosity=2).run(suite)
'''Generate test report using BeautifulReport'''
# BeautifulReport.BeautifulReport(suite).report(description="Same report from BeautifulReport", filename="reportBeautiful", report_dir='./Report')