国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄

這篇具有很好參考價(jià)值的文章主要介紹了Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

一.前言

1.1項(xiàng)目框架

項(xiàng)目如何使用框架: 本項(xiàng)目采用unitest框架

設(shè)計(jì)模式是如何應(yīng)用:本項(xiàng)目采用pageobject設(shè)計(jì)模式

UI對(duì)象庫(kù)思想

項(xiàng)目設(shè)計(jì)

一個(gè)模塊(被測(cè)項(xiàng)目的頁(yè)面)對(duì)應(yīng)一個(gè)py文件及一個(gè)測(cè)試類(測(cè)試文件)

每一個(gè)測(cè)試頁(yè)面(系統(tǒng)的頁(yè)面)中存儲(chǔ)頁(yè)面元素及此頁(yè)面中涉及到的功能

每一個(gè)用例組合在一個(gè)測(cè)試類里面生成一個(gè)py文件

項(xiàng)目目標(biāo)

我們?cè)趯?xiě)自動(dòng)化測(cè)試項(xiàng)目的時(shí)候一定要想好你的腳本都要哪些功能,頁(yè)面元素平凡改動(dòng)的時(shí)候是否需要大批量的修改腳本,及測(cè)試不同數(shù)據(jù)時(shí)是否也要修改腳本,那么能想到這些我們的初始目標(biāo)差不多就有了

1.生成測(cè)試用例執(zhí)行結(jié)果報(bào)告

2.生成測(cè)試用例執(zhí)行日志

3.用例執(zhí)行失敗或者執(zhí)行完成后自動(dòng)發(fā)送郵件報(bào)告

用例執(zhí)行失敗或者成功時(shí)截取圖片

5.數(shù)據(jù)驅(qū)動(dòng)(讀取測(cè)試數(shù)據(jù),減少腳本維護(hù)成本)

更多資料

1.2項(xiàng)目目錄結(jié)構(gòu)

Retail_TestPro

? ? Docs# 存放項(xiàng)目的相關(guān)文檔        

? ? ? ? 01測(cè)試計(jì)劃

? ? ? ? 02測(cè)試大綱

? ? ? ? 03測(cè)試用例

? ? ? ? 04測(cè)試報(bào)告

? ? ? ? 05測(cè)試進(jìn)度

? ? ? ? 06技術(shù)文檔

? ? ? ? 07測(cè)試申請(qǐng)

? ? Package# 存放第三方插件

? ? ? ? HTMLTestRunner.py

? ? Retail

? ? ? ? Config

? ? ? ? ? ? __init__.py

? ? ? ? ? ? Conf.py# 讀配置文件獲取項(xiàng)目跟目錄路徑 并獲取所有欲使用的目錄文件的路徑

? ? ? ? ? ? Config.ini# 存放項(xiàng)目跟目錄的路徑

? ? ? ? Data

? ? ? ? ? ? TestData

? ? ? ? ? ? ? ? __init__.py

? ? ? ? ? ? ? ? elementDate.xlsx# 存放項(xiàng)目中所有的元素信息及測(cè)試數(shù)據(jù)

? ? ? ? ? ? ? ? Email_receiver.txt# 存放郵件的接受者信息

? ? ? ? Report# 測(cè)試報(bào)告

? ? ? ? ? ? Image

? ? ? ? ? ? ? ? Fail# 存放用例執(zhí)行失敗時(shí)的截圖

? ? ? ? ? ? ? ? Pass# 存放用例執(zhí)行成功時(shí)的截圖

? ? ? ? ? ? Log# 存放用例執(zhí)行過(guò)程中的log信息

? ? ? ? ? ? TestReport# 存放測(cè)試用例執(zhí)行完成后生成的測(cè)試報(bào)告

? ? ? ? Test_case# 測(cè)試用例信息

? ? ? ? ? ? Models # 存放一些公共方法

? ? ? ? ? ? ? ? Doconfini.py# 讀配置文件

? ? ? ? ? ? ? ? Doexcel.py# 讀excel文件

? ? ? ? ? ? ? ? Driver.py# 存放driver

? ? ? ? ? ? ? ? Log.py# 生成log

? ? ? ? ? ? ? ? Myunit.py# 繼承unittest.Testcase

? ? ? ? ? ? ? ? Sendmail.py# 發(fā)送郵件

? ? ? ? ? ? ? ? Strhandle.py# 字符串處理

? ? ? ? ? ? ? ? Tcinfo.py# 測(cè)試用例基本信息

? ? ? ? ? ? ? ? Testreport.py# 測(cè)試報(bào)告

? ? ? ? ? ? Page_obj# 測(cè)試模塊

? ? ? ? ? ? ? ? Activerule_page.py

? ? ? ? ? ? ? ? Base_page.py

? ? ? ? ? ? ? ? Company_page.py

? ? ? ? ? ? ? ? Createrule_page.py

? ? ? ? ? ? ? ? Memberquery_page.py

? ? ? ? ? ? ? ? Modifypw_page.py

? ? ? ? ? ? ? ? Pointquery_page.py

? ? ? ? ? ? ? ? ActiveRuleTc.py

? ? ? ? ? ? ? ? CompanyQueryTc.py

? ? ? ? ? ? ? ? CreateRuleTc.py

? ? ? ? ? ? ? ? LoginTc.py

? ? ? ? ? ? ? ? MemberQueryTc.py

? ? ? ? ? ? ? ? ModifyPwTc.py

? ? ? ? ? ? ? ? PointQueryTc.py

? ? ? ? runTc.py# 執(zhí)行測(cè)試用例? ? ? ? ?

Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師?

二.項(xiàng)目代碼

1.config.ini (存放項(xiàng)目跟路徑)

1

2

[project]

project_path = D:\Petrochina_Retail_Test_Project

2.conf.py

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

'''

?Code description:read config.ini, get path

?Create time:

?Developer:

?'''

?import os

?import sys

?from retail.test_case.models.doconfIni import DoConfIni

??

?# 獲取當(dāng)前路徑

?currPath= \

?????os.path.split(os.path.realpath(__file__))[0]

??

?# 讀配置文件獲取項(xiàng)目路徑

?readConfig = \

?????DoConfIni()

?proPath = \

?????readConfig.getConfValue(os.path.join(currPath,'config.ini'),'project','project_path')

??

?# 獲取日志路徑

?logPath= \

?????os.path.join(proPath,'retail','report','Log')

??

?# 測(cè)試用例路徑

?tcPath = \

?????os.path.join(proPath,'retail','test_case')

??

?# 獲取報(bào)告路徑

?reportPath= \

?????os.path.join(proPath,'retail','report','TestReport')

??

?# 獲取測(cè)試數(shù)據(jù)路徑

?dataPath= \

?????os.path.join(proPath,'retail','data','TestData')

??

?# 保存截圖路徑

?# 錯(cuò)誤截圖

?failImagePath = os.path.join(proPath, 'retail', 'report', 'image','fail')

?# 成功截圖

?passImagePath = os.path.join(proPath, 'retail', 'report', 'image','pass')

??

?# 被調(diào)函數(shù)名稱

?funcName = sys._getframe().f_code.co_name

?# 被調(diào)函數(shù)所在行號(hào)

?funcNo = sys._getframe().f_back.f_lineno

??

?# 被調(diào)函數(shù)所在文件名稱

?funcFile= sys._getframe().f_code.co_filename

3.elementData.xlsx(json與yaml替換)

存放測(cè)試數(shù)據(jù)

4.公共方法models下面的文件

4.1doconfini.py

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

62

63

64

65

66

'''

Code description:read conf file

Create time:

Developer:

'''

import logging

import configparser

from retail.config.conf import *

from retail.test_case.models.log import Logger

log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

class DoConfIni(object):

????def __init__(self):

????????"""

????????:param filename:

????????"""

????????self.cf = configparser.ConfigParser()

????# 從ini文件中讀數(shù)據(jù)

????def getConfValue(self,filename,section,name):

????????"""

????????:param config:

????????:param name:

????????:return:

????????"""

????????try:

????????????self.cf.read(filename)

????????????value = self.cf.get(section,name)

????????except Exception as e:

????????????log.logger.exception('read file [%s] for [%s] failed , did not get the value' %(filename,section))

????????????raise e

????????else:

????????????log.logger.info('read excel value [%s] successed! ' %value)

????????????return value

????# 向ini文件中寫(xiě)數(shù)據(jù)

????def writeConfValue(self,filename, section, name, value):

????????"""

????????:param section: section

????????:param name: value name

????????:param value:? value

????????:return: none

????????"""

????????try:

????????????self.cf.add_section(section)

????????????self.cf.set(section, name, value)

????????????self.cf.write(open(filename, 'w'))

????????except Exception :

????????????log.logger.exception('section %s has been exist!' %section)

????????????raise configparser.DuplicateSectionError(section)

????????else:

????????????log.logger.info('write section'+section+'with value '+value+' successed!')

if __name__ == '__main__':

????file_path = currPath

????print(file_path)

????read_config = DoConfIni()

????value = read_config.getConfValue(os.path.join(currPath,'config.ini'),'project','project_path')

????print(value)

????read_config.writeConfValue(os.path.join(currPath,'config.ini'),'tesesection', 'name', 'hello word')

4.2doexcel.py

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

'''

?Code description:read excel.xlsx, get values

?Create time:

?Developer:

?'''

??

?import xlrd

?import os

?import logging

?from retail.config import conf

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

??

?class ReadExcel(object):

??

?????def __init__(self,fileName='elementDate.xlsx',sheetName='elementsInfo'):

?????????"""

??

?????????:param fileName:

?????????:param sheetName:

?????????"""

?????????try:

?????????????self.dataFile = os.path.join(conf.dataPath, fileName)

?????????????self.workBook = xlrd.open_workbook(self.dataFile)

?????????????self.sheetName = self.workBook.sheet_by_name(sheetName)

?????????except Exception:

?????????????log.logger.exception('init class ReadExcel fail', exc_info=True)

?????????????raise

?????????else:

?????????????log.logger.info('initing class ReadExcel')

?????# 讀excel中的數(shù)據(jù)

?????def readExcel(self,rownum,colnum):

?????????"""

??

?????????:param rownum:

?????????:param colnum:

?????????:return:

?????????"""

?????????try:

?????????????value = self.sheetName.cell(rownum,colnum).value

?????????except Exception:

?????????????log.logger.exception('read value from excel file fail', exc_info=True)

?????????????raise

?????????else:

?????????????log.logger.info('reading value [%s] from excel file [%s] completed' %(value, self.dataFile))

?????????????return value

??

?if __name__ == '__main__':

?????cellValue = ReadExcel().readExcel(1,3)

?????print((cellValue))

4.3log.py

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

'''

?Code description:log info

?Create time:

?Developer:

?'''

??

?import logging

?import time

??

?class Logger(object):

?????def __init__(self, logger, CmdLevel=logging.INFO, FileLevel=logging.INFO):

?????????"""

??

?????????:param logger:

?????????:param CmdLevel:

?????????:param FileLevel:

?????????"""

?????????self.logger = logging.getLogger(logger)

?????????self.logger.setLevel(logging.DEBUG)? # 設(shè)置日志輸出的默認(rèn)級(jí)別

?????????# 日志輸出格式

?????????fmt = logging.Formatter('%(asctime)s - %(filename)s:[%(lineno)s] - [%(levelname)s] - %(message)s')

?????????# 日志文件名稱

?????????# self.LogFileName = os.path.join(conf.log_path, "{0}.log".format(time.strftime("%Y-%m-%d")))# %H_%M_%S

?????????currTime = time.strftime("%Y-%m-%d")

?????????self.LogFileName = r'D:\Petrochina_Retail_Test_Project\retail\report\Log\log'+currTime+'.log'

?????????# 設(shè)置控制臺(tái)輸出

?????????# sh = logging.StreamHandler()

?????????# sh.setFormatter(fmt)

?????????# sh.setLevel(CmdLevel)# 日志級(jí)別

??

?????????# 設(shè)置文件輸出

?????????fh = logging.FileHandler(self.LogFileName)

?????????fh.setFormatter(fmt)

?????????fh.setLevel(FileLevel)# 日志級(jí)別

??

?????????# self.logger.addHandler(sh)

?????????self.logger.addHandler(fh)

??

?????# def debug(self, message):

?????#???? """

?????#

?????#???? :param message:

?????#???? :return:

?????#???? """

?????#???? self.logger.debug(message)

?????#

?????# def info(self,message):

?????#???? """

?????#

?????#???? :param message:

?????#???? :return:

?????#???? """

?????#???? self.logger.info(message)

?????#

?????# def warn(self,message):

?????#???? """

?????#

?????#???? :param message:

?????#???? :return:

?????#???? """

?????#???? self.logger.warning(message)

?????#

?????# def error(self,message):

?????#???? """

?????#

?????#???? :param message:

?????#???? :return:

?????#???? """

?????#???? self.logger.error(message)

?????#

?????# def criti(self,message):

?????#???? """

?????#

?????#???? :param message:

?????#???? :return:

?????#???? """

?????#???? self.logger.critical(message)

??

?if __name__ == '__main__':

?????logger = Logger("fox",CmdLevel=logging.DEBUG, FileLevel=logging.DEBUG)

?????logger.logger.debug("debug")

?????logger.logger.log(logging.ERROR,'%(module)s %(info)s',{'module':'log日志','info':'error'}) #ERROR,log日志 error

4.4sendmail.py

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

'''

?Code description:send email

?Create time:

?Developer:

?'''

??

?import smtplib

?from email.mime.text import MIMEText

?from email.header import Header

?import os

?from retail.config import conf

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__)

?#?? 郵件發(fā)送接口

?class SendMail(object):

?????'''

?????郵件配置信息

?????'''

?????def __init__(self,

??????????????????receiver,

??????????????????subject='Retail 系統(tǒng)測(cè)試報(bào)告',

??????????????????server='smtp.qq.com',

??????????????????fromuser='281754043@qq.com',

??????????????????frompassword='gifhhsbgqyovbhhc',

??????????????????sender='281754043@qq.com'):

?????????"""

??

?????????:param receiver:

?????????:param subject:

?????????:param server:

?????????:param fromuser:

?????????:param frompassword:

?????????:param sender:

?????????"""

??

?????????self._server = server

?????????self._fromuser = fromuser

?????????self._frompassword = frompassword

?????????self._sender = sender

?????????self._receiver = receiver

?????????self._subject = subject

??

?????def sendEmail(self, fileName):

?????????"""

??

?????????:param filename:

?????????:return:

?????????"""

?????????#?? 打開(kāi)報(bào)告文件讀取文件內(nèi)容

?????????try:

?????????????f = open(os.path.join(conf.reportPath, fileName), 'rb')

?????????????fileMsg = f.read()

?????????except Exception:

?????????????log.logger.exception('open or read file [%s] failed,No such file or directory: %s' %(fileName, conf.reportPath))

?????????????log.logger.info('open and read file [%s] successed!' %fileName)

?????????else:

?????????????f.close()

?????????????#?? 郵件主題

?????????????subject = 'Python test report' #

?????????????#?? 郵件設(shè)置

?????????????msg = MIMEText(fileMsg, 'html', 'utf-8')

?????????????msg['subject'] = Header(subject, 'utf-8')

?????????????msg['from'] = self._sender

?????????#?? 連接服務(wù)器,登錄服務(wù)器,發(fā)送郵件

?????????????try:

?????????????????smtp = smtplib.SMTP()

?????????????????smtp.connect(self._server)

?????????????????smtp.login(self._fromuser, self._frompassword)

?????????????except Exception:

?????????????????log.logger.exception('connect [%s] server failed or username and password incorrect!' %smtp)

?????????????else:

?????????????????log.logger.info('email server [%s] login success!' %smtp)

?????????????????try:

?????????????????????smtp.sendmail(self._sender, self._receiver, msg.as_string())

?????????????????except Exception:

?????????????????????log.logger.exception('send email failed!')

?????????????????else:

?????????????????????log.logger.info('send email successed!')

??

?#?? 從文件中讀取郵件接收人信息

?def getReceiverInfo(fileName):

?????'''

?????:param filename: 讀取接收郵件人信息

?????:return: 接收郵件人信息

?????'''

?????try:

?????????openFile = open(os.path.join(conf.dataPath, fileName))

?????except Exception:

?????????log.logger.exception('open or read file [%s] failed,No such file or directory: %s' %(fileName, conf.dataPath))

?????else:

?????????log.logger.info('open file [%s] successed!' %fileName)

?????????for line in openFile:

?????????????msg = [i.strip() for i in line.split(',')]

?????????????log.logger.info('reading [%s] and got receiver value is [%s]' %(fileName, msg))

?????????????return msg

??

?if __name__ == '__main__':

?????readMsg=getReceiverInfo('mail_receiver.txt')

?????sendmail = SendMail(readMsg)

?????sendmail.sendEmail('2021-04-21 17_44_04.html')

4.5strhandle.py

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

'''

?Code description: string handle

?Create time:

?Developer:

?'''

??

?import logging

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

?def strhandle(str):

?????"""

??

?????:param str:

?????:return:

?????"""

?????#初始化字符、數(shù)字、空格、特殊字符的計(jì)數(shù)

?????try:

?????????lowerCase = 0

?????????upperCase = 0

?????????number = 0

?????????other = 0

?????????for stritem in str:

??????????#如果在字符串中有小寫(xiě)字母,那么小寫(xiě)字母的數(shù)量+1

?????????????if stritem.islower():

?????????????????lowerCase += 1

?????????????#如果在字符串中有數(shù)字,那么數(shù)字的數(shù)量+1

?????????????elif stritem.isdigit():

?????????????????number += 1

?????????????elif stritem.isupper():# 大寫(xiě)字母

?????????????????upperCase +=1

?????????????#如果在字符串中有空格,那么空格的數(shù)量+1

?????????????else:

?????????????????other += 1

?????????return lowerCase, upperCase, number, other

?????except Exception as e:

?????????log.logger.exception('string handle error , please check!', exc_info=True)

?????????raise e

??

?if __name__=='__main__':

?????list = ['qwert','erwer']

?????lowercase, uppercase, number, other = strhandle(list[0])

?????print ("該字符串中的小寫(xiě)字母有:%d" %lowercase)

?????print ("該字符串中的大寫(xiě)寫(xiě)字母有:%d" %uppercase)

?????print ("該字符串中的數(shù)字有:%d" %number)

?????print ("該字符串中的特殊字符有:%d" %other)

4.6testreport.py

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

62

63

64

65

66

67

68

'''

?Code description:test report

?Create time:

?Developer:

?'''

??

?import time

?import logging

?import unittest

?from BeautifulReport import BeautifulReport

?import HTMLTestRunner

?from retail.config import conf

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

?# 用HTMLTestRunner 實(shí)現(xiàn)的測(cè)試報(bào)告

?def testreport():

?????"""

??

?????:return:

?????"""

?????currTime = time.strftime('%Y-%m-%d %H_%M_%S')

?????fileName = conf.reportPath + r'\report' + currTime + '.html'

?????try:

?????????fp = open(fileName, 'wb')

?????except Exception :

?????????log.logger.exception('[%s] open error cause Failed to generate test report' %fileName)

?????else:

?????????runner = HTMLTestRunner.HTMLTestRunner\

?????????????(stream=fp, title='Retail sys測(cè)試報(bào)告',

????????????????????????????????????????????????description='處理器:Intel(R) Core(TM) '

????????????????????????????????????????????????????????????'i5-6200U CPU @ 2030GHz 2.40 GHz '

?????????????????????????????????????????????????'內(nèi)存:8G 系統(tǒng)類型: 64位 版本: windows 10 家庭中文版')

?????????log.logger.info('successed to generate test report [%s]' %fileName)

?????????return runner, fp, fileName

?#

?def addTc(TCpath = conf.tcPath, rule = '*TC.py'):

?????"""

??

?????:param TCpath: 測(cè)試用例存放路徑

?????:param rule: 匹配的測(cè)試用例文件

?????:return:? 測(cè)試套件

?????"""

?????discover = unittest.defaultTestLoader.discover(TCpath, rule)

??

?????return discover

?# 用BeautifulReport模塊實(shí)現(xiàn)測(cè)試報(bào)告

?def runTc(discover):

?????"""

??

?????:param discover: 測(cè)試套件

?????:return:

?????"""

?????currTime = time.strftime('%Y-%m-%d %H_%M_%S')

?????fileName = currTime+'.html'

?????try:

?????????result = BeautifulReport(discover)

?????????result.report(filename=fileName, description='測(cè)試報(bào)告', log_path=conf.reportPath)

?????except Exception:

?????????log.logger.exception('Failed to generate test report', exc_info=True)

?????else:

?????????log.logger.info('successed to generate test report [%s]' % fileName)

?????????return fileName

??

?if __name__ == '__main__':

?????testreport()

?????suite = addTc(rule = '*TC.py')

?????runTc(suite)

4.7driver.py

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

62

63

64

65

66

67

'''

?Code description:save all driver info

?Create time:

?Developer:

?'''

??

?from selenium import webdriver

?import logging

?import sys

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

?class WDriver(object):

??

?????# Firefox driver

?????def fireFoxDriver(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????self.driver = webdriver.Firefox()

?????????except Exception as e:

?????????????log.logger.exception('FireFoxDriverServer.exe executable needs to be in PATH. Please download!', exc_info=True)

?????????????raise e

?????????else:

?????????????log.logger.info('%s:found the Firefox driver [%s] successed !' %(sys._getframe().f_code.co_name,self.driver))

?????????????return self.driver

??

?????# chrom driver

?????def chromeDriver(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????# option = webdriver.ChromeOptions()# 實(shí)現(xiàn)不打開(kāi)瀏覽器 執(zhí)行web自動(dòng)化測(cè)試腳本

?????????????# option.add_argument('headless')#

?????????????# self.driver = webdriver.Chrome(chrome_options=option)

?????????????self.driver = webdriver.Chrome()

?????????except Exception as e:

?????????????log.logger.exception('ChromeDriverServer.exe executable needs to be in PATH. Please download!',

??????????????????????????????????exc_info=True)

?????????????raise e

?????????else:

?????????????log.logger.info('%s:found the chrome driver [%s] successed !' % (sys._getframe().f_code.co_name, self.driver))

?????????????return self.driver

??

?????# Ie driver

?????def ieDriver(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????self.driver = webdriver.Ie()

?????????except Exception as e:

?????????????log.logger.exception('IEDriverServer.exe executable needs to be in PATH. Please download!',

??????????????????????????????????exc_info=True)

?????????????raise e

?????????else:

?????????????log.logger.info('%s:found the IE driver [%s] successed !' % (sys._getframe().f_code.co_name, self.driver))

?????????????return self.driver

??

?if __name__ == '__main__':

?????WDrive=WDriver()

?????WDrive.fireFoxDriver()

4.8myunittest.py

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

'''

?Code description:unittest framwork

?Create time:

?Developer:

?'''

??

?from retail.test_case.models.driver import WDriver

?import logging

?import unittest

?from retail.test_case.page_obj.login_page import LoginPage

?from retail.test_case.models.log import Logger

?from selenium import webdriver

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

?class MyunitTest(unittest.TestCase):

?????"""

??

?????"""

??

?????# add by xuechao at 2018.09.19

?????@classmethod

?????def setUpClass(cls): # 一個(gè)測(cè)試類(文件)執(zhí)行一次打開(kāi)瀏覽器, 節(jié)約每個(gè)用例打開(kāi)一次瀏覽器的時(shí)間

??

?????????#cls.driver = WDriver().fireFoxDriver()

?????????cls.driver = WDriver().chromeDriver()

?????????cls.driver.maximize_window()

?????????log.logger.info('opened the browser successed!')

?????# ----------------------------

??

?????def setUp(self):

?????????"""

??

?????????:return:

?????????"""

?????????self.login = LoginPage(self.driver)

?????????self.login.open()

?????????log.logger.info('************************starting run test cases************************')

??

?????def tearDown(self):

?????????"""

??

?????????:return:

?????????"""

?????????self.driver.refresh()

?????????log.logger.info('************************test case run completed************************')

??

?????# add by linuxchao at 2018.09.19

?????@classmethod

?????def tearDownClass(cls):

?????????cls.driver.quit()

?????????log.logger.info('quit the browser success!')

?????#----------------------------

?if __name__ == '__main__':

?????unittest.main()

4.9結(jié)束語(yǔ)

目前為止,我需要的所有的公共方法都編寫(xiě)完了, 后期再需要?jiǎng)e的方法可以加,下面我們就開(kāi)始編寫(xiě)我們的測(cè)試用例,由于我們使用的是PageObject模式,那么我們需要設(shè)計(jì)一個(gè)basepage頁(yè)面,所有的頁(yè)面或者說(shuō)模塊全部繼承這個(gè)basepage,basepage主要編寫(xiě)所有頁(yè)面的公共方法

5.base_page.py

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

'''

Code description: base page 封裝一些公共方法

Create time:

Developer:

'''

from selenium.webdriver.support.wait import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

import os

import logging

import sys

from retail.test_case.models.log import Logger

from retail.config import conf

from retail.test_case.models.doexcel import ReadExcel

eleData = ReadExcel() # 存儲(chǔ)系統(tǒng)所有的元素?cái)?shù)據(jù)

testLoginData = ReadExcel('elementDate.xlsx', 'userNamePw') # 登錄模塊測(cè)試數(shù)據(jù)

modifyPwData = ReadExcel('elementDate.xlsx', 'modifyPw') # 修改密碼模塊測(cè)試數(shù)據(jù)

queryData = ReadExcel('elementDate.xlsx', 'queryData')

log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

class BasePage(object):

????"""主菜單"""

????menuList = \

????????[(By.LINK_TEXT, eleData.readExcel(7, 3)), # 權(quán)限管理

????????(By.LINK_TEXT, eleData.readExcel(8, 3)), # 會(huì)員檔案

????????(By.LINK_TEXT, eleData.readExcel(9, 3)), # 積分消費(fèi)查詢

????????(By.LINK_TEXT, eleData.readExcel(10, 3)), # 功能演示

????????(By.LINK_TEXT, eleData.readExcel(11, 3)), # 待辦工作

????????(By.LINK_TEXT, eleData.readExcel(12, 3)), # 報(bào)表

????????(By.LINK_TEXT, eleData.readExcel(13, 3)), # 積分規(guī)則/活動(dòng)查詢

????????(By.LINK_TEXT, eleData.readExcel(14, 3))] # 積分規(guī)則/活動(dòng)申請(qǐng)

????def __init__(self, driver,url='http://11.11.164.134:9081/rmms/modules/ep.rmms.portal/login/login.jsp'):

????????"""

????????:param driver:

????????:param url:

????????"""

????????self.driver = driver

????????self.base_url = url

????def _open(self,url):

????????"""

????????:param url:

????????:return:

????????"""

????????try:

????????????self.driver.get(url)

????????????self.driver.implicitly_wait(10)

????????except Exception as e:

????????????log.logger.exception(e, exc_info=True)

????????????raise ValueError('%s address access error, please check!' %url)

????????else:

????????????log.logger.info('%s is accessing address %s at line[46]' %(sys._getframe().f_code.co_name,url))

????def open(self):

????????"""

????????:return:

????????"""

????????self._open(self.base_url)

????????log.logger.info('%s loading successed!' %self.base_url)

????????return self.base_url

????# *loc 代表任意數(shù)量的位置參數(shù)

????def findElement(self, *loc):

????????"""

????????查找單一元素

????????:param loc:

????????:return:

????????"""

????????try:

????????????WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(loc))

????????????# log.logger.info('The page of %s had already find the element %s'%(self,loc))

????????????# return self.driver.find_element(*loc)

????????except Exception as e:

????????????log.logger.exception('finding element timeout!, details' ,exc_info=True)

????????????raise e

????????else:

????????????log.logger.info('The page of %s had already find the element %s' % (self, loc))

????????????return self.driver.find_element(*loc)

????def findElements(self, *loc):

????????"""

????????查找一組元素

????????:param loc:

????????:return:

????????"""

????????try:

????????????WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(loc))

????????????# log.logger.info('The page of %s had already find the element %s' % (self, loc))

????????????# return self.driver.find_elements(*loc)

????????except Exception as e:

????????????log.logger.exception('finding element timeout!, details', exc_info=True)

????????????raise e

????????else:

????????????log.logger.info('The page of %s had already find the element %s' % (self, loc))

????????????return self.driver.find_elements(*loc)

????def inputValue(self, inputBox, value):

????????"""

????????后期修改其他頁(yè)面直接調(diào)用這個(gè)函數(shù)

????????:param inputBox:

????????:param value:

????????:return:

????????"""

????????inputB = self.findElement(*inputBox)

????????try:

????????????inputB.clear()

????????????inputB.send_keys(value)

????????except Exception as e:

????????????log.logger.exception('typing value error!', exc_info=True)

????????????raise e

????????else:

????????????log.logger.info('inputValue:[%s] is receiveing value [%s]' % (inputBox, value))

????# 獲取元素?cái)?shù)據(jù)

????def getValue(self, *loc):

????????"""

????????:param loc:

????????:return:

????????"""

????????element = self.findElement(*loc)

????????try:

????????????value = element.text

????????????#return value

????????except Exception:

????????????#element = self.find_element_re(*loc) # 2018.09.21 for log

????????????value = element.get_attribute('value')

????????????log.logger.info('reading the element [%s] value [%s]' % (loc, value))

????????????return value

????????except:

????????????log.logger.exception('read value failed', exc_info=True)

????????????raise Exception

????????else:

????????????log.logger.info('reading the element [%s] value [%s]' % (loc,value))

????????????return value

????def getValues(self, *loc):

????????"""

????????:param loc:

????????:return:

????????"""

????????value_list = []

????????try:

????????????for element in self.findElements(*loc):

????????????????value = element.text

????????????????value_list.append(value)

????????except Exception as e:

????????????log.logger.exception('read value failed', exc_info=True)

????????????raise e

????????else:

????????????log.logger.info('reading the element [%s] value [%s]'% (loc,value_list))

????????????return value_list

????# 執(zhí)行js腳本

????def jScript(self,src):

????????"""

????????:param src:

????????:return:

????????"""

????????try:

????????????self.driver.excute_script(src)

????????except Exception as e:

????????????log.logger.exception('execute js script [%s] failed ' %src)

????????????raise e

????????else:

????????????log.logger.info('execute js script [%s] successed ' %src)

????# 判斷元素是否存在

????def isElementExist(self, element):

????????"""

????????:param element:

????????:return:

????????"""

????????try:

????????????WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(element))

????????except:

????????????# log.logger.exception('The element [%s] not exist', exc_info=True)

????????????return False

????????else:

????????????# log.logger.info('The element [%s] have existed!' %element)

????????????return True

????# 截圖

????def saveScreenShot(self, filename):

????????"""

????????:param filename:

????????:return:

????????"""

????????list_value = []

????????list = filename.split('.')

????????for value in list:

????????????list_value.append(value)

????????if list_value[1] == 'png' or list_value[1] == 'jpg' or list_value[1] == 'PNG' or list_value[1] == 'JPG':

????????????if 'fail' in list_value[0].split('_'):

????????????????try:

????????????????????self.driver.save_screenshot(os.path.join(conf.failImagePath, filename))

????????????????except Exception:

????????????????????log.logger.exception('save screenshot failed !', exc_info=True)

????????????????else:

????????????????????log.logger.info('the file [%s]? save screenshot successed under [%s]' % (filename, conf.failImagePath))

????????????elif 'pass' in list_value[0]:

????????????????try:

????????????????????self.driver.save_screenshot(os.path.join(conf.passImagePath, filename))

????????????????except Exception:

????????????????????log.logger.exception('save screenshot failed !', exc_info=True)

????????????????else:

????????????????????log.logger.info(

????????????????????????'the file [%s]? save screenshot successed under [%s]' % (filename, conf.passImagePath))

????????????else:

????????????????log.logger.info('save screenshot failed due to [%s] format incorrect' %filename)

????????else:

????????????log.logger.info('the file name of [%s] format incorrect cause save screenshot failed, please check!' % filename)

????# 接受錯(cuò)誤提示框

????def accept(self, *loc):

????????"""

????????:return:

????????"""

????????self.findElement(*loc).click()

????????log.logger.info('closed the error information fram successed!')

if __name__ == '__main__':

????pass

6.login_page.py(登陸頁(yè)面)

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

'''

?Code description: login page

?Create time:

?Developer:

?'''

??

?from selenium.webdriver.common.by import By

?import logging

?import sys

?from retail.test_case.page_obj.base_page import BasePage, eleData, testLoginData

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

??

?class LoginPage(BasePage):

??

?????"""用戶名,密碼,登錄按鈕,保存信息,錯(cuò)誤提示"""

?????userNameEle = (By.ID, eleData.readExcel(1, 3))

?????passWordEle = (By.ID, eleData.readExcel(2, 3))

?????loginBtnEle = (By.ID, eleData.readExcel(3, 3))

?????saveInfoEle = (By.NAME, eleData.readExcel(4, 3))

?????errorMessage = (By.ID, eleData.readExcel(5, 3))

?????quitBtn = (By.ID, eleData.readExcel(6, 3))

??

?????# 用戶名和密碼

?????unpwData = \

?????????[[testLoginData.readExcel(1, 0), testLoginData.readExcel(1, 1)],# 正確的用戶名和正確的密碼

??????????[testLoginData.readExcel(2, 0), testLoginData.readExcel(2, 1)],# 錯(cuò)誤的用戶名和正確的密碼

??????????[testLoginData.readExcel(3, 0), testLoginData.readExcel(3, 1)],# 空的用戶名和正確的密碼

??????????[testLoginData.readExcel(4, 0), testLoginData.readExcel(4, 1)],# 錯(cuò)誤的用戶名和錯(cuò)誤的密碼

??????????[testLoginData.readExcel(5, 0), testLoginData.readExcel(5, 1)],# 正確的用戶名和空密碼

??????????[testLoginData.readExcel(6, 0), testLoginData.readExcel(6, 1)],# 正確的用戶名和錯(cuò)誤的密碼

??????????[testLoginData.readExcel(7, 0), testLoginData.readExcel(7, 1)]]# 空用戶名和空密碼

??

?????# 登錄按鈕

?????def clickLoginBtn(self):

?????????"""

??

?????????:return:

?????????"""

?????????element = self.findElement(*self.loginBtnEle)

?????????element.click()

?????????log.logger.info('%s ,logining....!' % sys._getframe().f_code.co_name)

?????# 登錄失敗時(shí)提示

?????def getFailedText(self):

?????????"""

??

?????????:return:

?????????"""

?????????info = self.findElement(*self.errorMessage).text

?????????log.logger.info('login failed : %s' %info)

?????????return info

??

?????# 登錄失敗時(shí)彈出的alert

?????def handleAlert(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????alert = self.driver.switch_to_alert()

?????????????text = alert.text

?????????????alert.accept()

?????????except Exception:

?????????????log.logger.exception('handle alert failed, please check the details' ,exc_info=True)

?????????????raise

?????????else:

?????????????log.logger.info('login failed ,%s handle alert successed alert info: %s!' %(sys._getframe().f_code.co_name, text))

?????????????return text

??

?????# 統(tǒng)一登錄函數(shù)

?????def loginFunc(self, username='rmln', password='qwert1234!@#'):

?????????"""

?????????:param username:

?????????:param password:

?????????:return:

?????????"""

?????????self.inputValue(self.userNameEle, username)

?????????self.inputValue(self.passWordEle, password)

?????????self.clickLoginBtn()

??

?????# 清空輸入框數(shù)據(jù)

?????def clearValue(self, element):

??

?????????empty = self.findElement(*element)

?????????empty.clear()

?????????log.logger.info('emptying value.......')

??

?????# 推出

?????def quit(self):

?????????self.findElement(*self.quitBtn).click()

?????????log.logger.info('quit')

??

?if __name__ == '__main__':

?????pass

7.LoginTC.py(登陸測(cè)試用例)

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

"""

Code description:login testcase

Create time:

Developer:

"""

import unittest

import time

import logging

import sys

from retail.test_case.models.myunit import MyunitTest

from retail.test_case.models.log import Logger

log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

class Login_TC(MyunitTest):

????"""登錄模塊測(cè)試用例"""

????def test_login_success_correct_username_password(self):

????????"""用戶名正確,密碼正確,登錄成功"""

????????self.login.loginFunc()

????????currUrl = self.driver.current_url # 獲取當(dāng)前的url地址

????????try:

????????????self.assertIn('main', currUrl, 'main not in current url!')

????????except Exception:

????????????self.login.saveScreenShot('correct_username_password_fail.png')

????????????raise

????????else:

????????????self.login.saveScreenShot('correct_username_password_pass.png')

????????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login_failed_incorrect_username(self):

????????"""用戶名錯(cuò)誤,密碼正確,登錄失敗"""

????????self.login.loginFunc(self.login.unpwData[1][0], self.login.unpwData[1][1])

????????failText = self.login.getFailedText()

????????self.assertEqual('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, '提示信息錯(cuò)誤')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login_failed_incorrect_password(self):

????????"""用戶名正確,密碼錯(cuò)誤,登錄失敗"""

????????self.login.loginFunc(self.login.unpwData[5][0], self.login.unpwData[5][1])

????????failText = self.login.getFailedText()

????????self.assertEqual('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, '提示信息錯(cuò)誤')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login_failed_username_password_blank(self):

????????"""用戶名為空,密碼為空,登錄失敗"""

????????self.login.loginFunc(self.login.unpwData[6][0], self.login.unpwData[6][1])

????????failText = self.login.handleAlert() # 獲取alert的提示信息

????????self.assertEqual('請(qǐng)?zhí)顚?xiě)用戶名', failText, '提示信息錯(cuò)誤')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login_failed_password_blank(self):

????????"""用戶名正確,密碼為空,登錄失敗"""

????????self.login.loginFunc(self.login.unpwData[4][0], self.login.unpwData[4][1])

????????failText = self.login.handleAlert() # 獲取alert的提示信息

????????self.assertEqual('請(qǐng)?zhí)顚?xiě)用戶密碼', failText, '提示信息錯(cuò)誤')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login_failed_unpw_incorrect(self):

????????"""用戶名錯(cuò)誤,密碼錯(cuò)誤,登錄失敗"""

????????# try:

????????self.login.loginFunc(self.login.unpwData[3][0], self.login.unpwData[4][0])

????????failText = self.login.getFailedText()

????????self.assertEqual ('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, 'failed')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

????def test_login(self):

????????"""循環(huán)測(cè)試登錄功能"""

????????for listitem in self.login.unpwData:

????????????self.login.inputValue(self.login.userNameEle,listitem[0])

????????????time.sleep(2)

????????????self.login.inputValue(self.login.passWordEle,listitem[1])

????????????time.sleep(2)

????????????self.login.clickLoginBtn()

????????????time.sleep(2)

????????????if listitem[0] =='rmln' and listitem[1] == 'qwert1234!@#':

????????????????currUrl = self.driver.current_url

????????????????self.assertIn ('main' , currUrl)

????????????????self.login.quit()

????????????elif listitem[0] == 'rmln' and listitem[1] != 'qwert1234!@#':

????????????????if listitem[1] == '':

????????????????????failText = self.login.handleAlert()? # 獲取alert的提示信息

????????????????????self.assertEqual('請(qǐng)?zhí)顚?xiě)用戶密碼', failText, '提示信息錯(cuò)誤')

????????????????else:

????????????????????failText = self.login.getFailedText()

????????????????????self.assertEqual('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, '提示信息錯(cuò)誤')

????????????elif listitem[0] != 'rmln' and listitem[1] == 'qwert1234!@#':

????????????????if listitem[0]=='':

????????????????????failText = self.login.handleAlert()? # 獲取alert的提示信息

????????????????????self.assertEqual('請(qǐng)?zhí)顚?xiě)用戶名', failText, '提示信息錯(cuò)誤')

????????????????else:

????????????????????failText = self.login.getFailedText()

????????????????????self.assertEqual('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, '提示信息錯(cuò)誤')

????????????elif listitem[0] == listitem[1] == '':

????????????????failText = self.login.handleAlert()? # 獲取alert的提示信息

????????????????self.assertEqual('請(qǐng)?zhí)顚?xiě)用戶名', failText, '提示信息錯(cuò)誤')

????????????else:

????????????????failText = self.login.getFailedText()

????????????????self.assertEqual('輸入的用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!', failText, '提示信息錯(cuò)誤')

????????log.logger.info('%s->run completed! please check the test report' % (sys._getframe().f_code.co_name))

if __name__ == '__main__':

????unittest.main()

8.modifypw_page.py(修改密碼頁(yè)面)

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

'''

?Code description:modify password page

?Create time:

?Developer:

?'''

??

?import logging

?import time

?from selenium.webdriver.common.by import By

?from selenium.webdriver.common.action_chains import ActionChains

?from retail.test_case.page_obj.base_page import BasePage, eleData, modifyPwData

?from retail.test_case.models.log import Logger

??

?log = Logger(__name__, CmdLevel=logging.INFO, FileLevel=logging.INFO)

?class PrimaryMenu(BasePage):

??

?????"""密碼數(shù)據(jù)"""

?????pwdList = \

?????????[[modifyPwData.readExcel(1, 0), modifyPwData.readExcel(1, 1), modifyPwData.readExcel(1, 2)],

??????????[modifyPwData.readExcel(2, 0), modifyPwData.readExcel(2, 1), modifyPwData.readExcel(2, 2)],

??????????[modifyPwData.readExcel(3, 0), modifyPwData.readExcel(3, 1), modifyPwData.readExcel(3, 2)],

??????????[modifyPwData.readExcel(4, 0), modifyPwData.readExcel(4, 1), modifyPwData.readExcel(4, 2)],

??????????[modifyPwData.readExcel(5, 0), modifyPwData.readExcel(5, 1), modifyPwData.readExcel(5, 2)]]

??

?????"""權(quán)限管理下拉菜單"""

?????menuPersonal = (By.LINK_TEXT, eleData.readExcel(15, 3))

?????menuModifyPwd = (By.LINK_TEXT, eleData.readExcel(16, 3))

??

?????"""密碼修改"""

?????oldPwd = (By.ID, eleData.readExcel(17, 3))

?????newPwd = (By.ID, eleData.readExcel(18, 3))

?????commitPwd = (By.ID, eleData.readExcel(19, 3))

??

?????"""錯(cuò)誤提示框及確定"""

?????errMessage = (By.XPATH, eleData.readExcel(20, 3))

?????closeBtn = (By.CSS_SELECTOR, eleData.readExcel(21, 3))

??

?????"""密碼說(shuō)明"""

?????readMe = (By.ID, eleData.readExcel(22, 3))

??

?????"""保存"""

?????saveBtn = (By.XPATH, eleData.readExcel(23, 3))

??

?????#?? 主菜單

?????def findMenu(self,*menuList):

?????????"""

??

?????????:param menu_list:

?????????:return:

?????????"""

?????????return self.findElement(*menuList)

??

?????#?? 舊密碼輸入框

?????def inputOldPw(self, oldPwd=''):

?????????""""""

?????????try:

?????????????self.findElement(*self.oldPwd).clear()

?????????????self.findElement(*self.oldPwd).send_keys(oldPwd)

?????????except Exception:

?????????????log.logger.exception('input Pw [%s] for oldPw [%s] fail' %(oldPwd, self.oldPwd))

?????????????raise

?????????else:

?????????????log.logger.info('inputing Pw [%s] for oldPw [%s] ' % (oldPwd, self.oldPwd))

?????#?? 新密碼輸入框

?????def inputNewPw(self, newPwd=''):

?????????"""

??

?????????:param newPwd:

?????????:return:

?????????"""

?????????try:

?????????????self.findElement(*self.newPwd).clear()

?????????????self.findElement(*self.newPwd).send_keys(newPwd)

?????????except Exception:

?????????????log.logger.exception('input Pw [%s] for newPw [%s] fail' % (newPwd, self.newPwd))

?????????????raise

?????????else:

?????????????log.logger.info('inputing Pw [%s] for newPw [%s] ' % (newPwd, self.newPwd))

?????#?? 確認(rèn)密碼輸入框

?????def inputConfirmPw(self, confirmPwd=''):

?????????"""

??

?????????:param confirmPwd:

?????????:return:

?????????"""

?????????try:

?????????????self.findElement(*self.commitPwd).clear()

?????????????self.findElement(*self.commitPwd).send_keys(confirmPwd)

?????????except Exception:

?????????????log.logger.exception('input Pw [%s] for commitPw [%s] fail' %(confirmPwd, self.commitPwd))

?????????????raise

?????????else:

?????????????log.logger.info('inputing Pw [%s] for commitPw [%s] ' %(confirmPwd, self.commitPwd))

?????#?? 保存

?????def saveButton(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????self.driver.implicitly_wait(5)

?????????????clickbutton = self.findElement(*self.saveBtn)

?????????????time.sleep(1)

?????????????clickbutton.click()

?????????except Exception:

?????????????log.logger.exception('click save button fail')

?????????????raise

?????????else:

?????????????log.logger.info('clciking the button')

??

?????#?? 修改密碼功能菜單

?????def modifyPwMenu(self):

?????????"""

??

?????????:return:

?????????"""

?????????try:

?????????????self.findElement(*self.menuList[0]).click()

?????????????self.findElement(*self.menuPersonal).click()

?????????????self.findElement(*self.menuModifyPwd).click()

?????????except Exception:

?????????????log.logger.exception('not found menu [%s]-[%s]-[%s]' %(self.menuList[0], self.menuPersonal, self.menuModifyPwd))

?????????????raise

?????????else:

?????????????log.logger.info('finding menu [%s]-[%s]-[%s]' %(self.menuList[0], self.menuPersonal, self.menuModifyPwd))

?????????????self.driver.implicitly_wait(2)

??

?????#?? 修改密碼

?????def modifyPw(self, list):

?????????"""

??

?????????:param list:

?????????:return:

?????????"""

?????????try:

?????????????self.inputOldPw(list[0])

?????????????self.inputNewPw(list[1])

?????????????self.inputConfirmPw(list[2])

?????????????self.saveButton()

?????????except Exception:

?????????????log.logger.exception('input oldpw/newpw/commitpw [%s]/[%s]/[%s] fail' %(list[0], list[1], list[2]))

?????????????raise

?????????else:

?????????????log.logger.info('modifing pw [%s]/[%s]/[%s]' %(list[0], list[1], list[2]))

??

?????#?? 錯(cuò)誤提示框

?????def errorDialog(self, commit_btn = (By.ID,'unieap_form_Button_1_unieap_input')):

?????????"""

?????????:type commit_btn: 元祖

?????????"""

??

?????????try:

?????????????messages_frame = self.findElement(*self.errMessage)

?????????????text = messages_frame.text

?????????????element = self.findElement(*commit_btn)

?????????????time.sleep(2)

?????????????action = ActionChains(self.driver)

?????????????action.move_to_element(element).perform()

?????????????time.sleep(2)

?????????????element.click()

?????????????action.reset_actions() # 釋放鼠標(biāo)

?????????except Exception:

?????????????log.logger.exception('close errMsgFram [%s] or get text [%s]fail' %(self.errMessage))

?????????????raise

?????????else:

?????????????log.logger.info('close errMsgFram [%s] and get text [%s] success' %(self.errMessage, text))

?????????????return text

??

?????# 關(guān)閉提示框

?????def closeErrMsg(self, element):

?????????try:

?????????????ele = self.findElement(*element)

?????????????action = ActionChains(self.driver)

?????????????action.move_to_element(ele).perform()

?????????????time.sleep(2)

?????????????ele.click()

?????????????action.reset_actions()

?????????except Exception:

?????????????log.logger.exception('close the err msg ifram fail', exc_info=True)

?????????????raise

?????????else:

?????????????log.logger.info('closing the err msg ifram success!')

??

?if __name__ == '__main__':

?????pass

9.ModifyPw.py(修改密碼測(cè)試用例)

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

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

'''

?Code description:權(quán)限管理/個(gè)人設(shè)置/密碼修改 testcase

?Create time:

?Developer:

?'''

??

?import time

?from retail.test_case.models.myunit import MyunitTest

?from retail.test_case.page_obj.modifypw_page import PrimaryMenu

?from retail.test_case.models.strhandle import strhandle

??

?class ModifyPw_TC(MyunitTest):

??

?????"""權(quán)限管理/個(gè)人設(shè)置/密碼修改模塊測(cè)試用例"""

??

?????def test_menu_is_display(self):

?????????"""主菜單校驗(yàn)"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????time.sleep(4)

?????????num = 0

?????????for menu_item in menu.menuList: # 循環(huán)遍歷并斷言菜單是否正確

?????????????self.assertEqual(menu.menuList[num][1],(menu.findMenu(*menu_item).text),'菜單不存在')

?????????????num=num+1

??

?????def test_modify_password_len(self):

?????????"""舊密碼非空,新密碼長(zhǎng)度小于4位,確認(rèn)密碼非空,修改密碼失敗,彈窗提示"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????menu.modifyPw(menu.pwdList[0]) # 修改密碼

?????????text = menu.errorDialog(menu.closeBtn)

?????????self.assertIn('密碼長(zhǎng)度至少 4 位!', text, '提示信息錯(cuò)誤') # 密碼長(zhǎng)度不滿足時(shí)斷言提示信息

??

?????def test_modify_password_strebgth(self):

?????????"""舊密碼非空,新密碼長(zhǎng)度大于4且強(qiáng)度不夠,確認(rèn)密碼非空,修改密碼失敗,彈窗提示"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????menu.modifyPw(menu.pwdList[1]) # 修改密碼

?????????text = menu.errorDialog(menu.closeBtn)

?????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!') # 密碼強(qiáng)度不滿足時(shí)斷言提示信息

??

?????def test_modify_password_incorrect(self):

?????????"""舊密碼不正確非空,新密碼等于確認(rèn)密碼且滿足條件,修改密碼失敗,彈窗提示"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????menu.modifyPw(menu.pwdList[2]) # 修改密碼

?????????text = menu.errorDialog(menu.closeBtn)

?????????self.assertIn('舊密碼輸入錯(cuò)誤!', text, '舊密碼輸入錯(cuò)誤!') # 新密碼和確認(rèn)碼不同時(shí)斷言提示信息

??

?????def test_modify_password_difference(self):

?????????"""舊密碼非空,新密碼不等于確認(rèn)密碼且新密碼滿足條件,修改密碼失敗,彈窗提示"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????menu.modifyPw(menu.pwdList[3]) # 修改密碼

?????????text = menu.errorDialog(menu.closeBtn)

?????????self.assertIn('兩次輸入的新密碼不同!', text, '兩次輸入的新密碼不同!') # 新密碼和確認(rèn)碼不同時(shí)斷言提示信息

??

?????def test_modify_password_all_blank(self):

?????????"""舊密碼,新密碼,確認(rèn)密碼任意為空,修改密碼失敗,彈窗提示"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????menu.modifyPw(menu.pwdList[4]) # 修改密碼

?????????text = menu.errorDialog(menu.closeBtn)

?????????self.assertIn('該輸入項(xiàng)的值不能為空!', text, ' 該輸入項(xiàng)的值不能為空!') # 所有密碼均為空時(shí)斷言提示信息

??

?????def test_modify_password(self):

?????????"""循環(huán)校驗(yàn)提示信息"""

?????????self.login.loginFunc()

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu() # 查找修改密碼頁(yè)面

?????????error_list = []

?????????for list in range(len(menu.pwdList)):

?????????????menu.modifyPw(menu.pwdList[list])

?????????????if menu.isElementExist(menu.errMessage):

?????????????????text = menu.errorDialog(menu.closeBtn) # 這里只判斷是否有提示框彈出,如有說(shuō)明修改失敗,沒(méi)有或者其他提示框默認(rèn)為修改成功

?????????????????error_list.append(text)

?????????????else:

?????????????????self.assertTrue(menu.isElementExist(*menu.errMessage), 'error fram not exist, please open bug')

?????????self.assertEqual('密碼長(zhǎng)度至少 4 位!',error_list[0],'log infomation error!')

?????????self.assertEqual('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', error_list[1], 'log infomation error!')

?????????self.assertEqual('舊密碼輸入錯(cuò)誤!', error_list[2], 'log infomation error!')

?????????self.assertEqual('兩次輸入的新密碼不同!', error_list[3], 'log infomation error!')

?????????self.assertEqual('該輸入項(xiàng)的值不能為空!', error_list[4], 'log infomation error!')

??

?????def test_modifypw(self):

?????????"""循環(huán)測(cè)試修改密碼功能"""

?????????self.login.loginFunc()# 登錄

?????????menu = PrimaryMenu(self.driver)

?????????menu.modifyPwMenu()? # 查找修改密碼頁(yè)面

?????????for item in menu.pwdList:

?????????????menu.modifyPw(item)

?????????????if menu.isElementExist(menu.errMessage):? # 如果存在提示框 再斷言提示信息是否正確

?????????????????if item[0] != '' and len(item[1]) < 4? and item[2] !='': # 新密碼長(zhǎng)度校驗(yàn)

?????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????try:

?????????????????????????self.assertEqual('密碼長(zhǎng)度至少 4 位!',text,'the message incorrect!')

?????????????????????except Exception:

?????????????????????????menu.saveScreenShot('fail_密碼長(zhǎng)度.png')

?????????????????????????raise

?????????????????elif item[0] != '' and len(item[1]) >= 4 and item[2] !='': # 新密碼強(qiáng)度校驗(yàn) ['a', 'qwert', 'qwert'],

?????????????????????lowercase, uppercase, number, other=strhandle(item[1])

?????????????????????if lowercase > 0 and uppercase > 0 and number == 0 and other == 0: # 小寫(xiě) 大寫(xiě)

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif uppercase > 0 and other > 0 and number == 0 and lowercase == 0: # 大寫(xiě) 特殊字符

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase >0 and other > 0 and number == 0 and uppercase == 0: # 小寫(xiě) 特殊字符

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase == 0 and other == 0 and number > 0 and uppercase > 0:? # 大寫(xiě) 數(shù)字

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase > 0 and other == 0 and number > 0 and uppercase == 0:? # 小寫(xiě) 數(shù)字

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase > 0 and other == 0 and number == 0 and uppercase == 0:

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase == 0 and other > 0 and number == 0 and uppercase == 0:

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase == 0 and other == 0 and number > 0 and uppercase == 0:

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif lowercase == 0 and other == 0 and number == 0 and uppercase > 0:

?????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????self.assertIn('密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!', text, ' 密碼強(qiáng)度不夠,請(qǐng)重新輸入密碼!')

?????????????????????elif item[0] != 'qwert1234!@#' and item[1] == item[2]:# >= 4

?????????????????????????lowercase, uppercase, number, other = strhandle(item[1])

?????????????????????????if (lowercase > 0 and uppercase > 0 and number > 0) or (

?????????????????????????????????????lowercase > 0 and uppercase > 0 and other > 0) or (

?????????????????????????????????????number > 0 and other > 0 and lowercase > 0) or (

?????????????????????????????????????number > 0 and other > 0 and uppercase > 0):

?????????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????????self.assertIn('舊密碼輸入錯(cuò)誤!', text, '舊密碼輸入錯(cuò)誤!')? # 新密碼和確認(rèn)碼不同時(shí)斷言提示信息

?????????????????????elif item[0] == 'qwert1234!@#$' and item[1] != item[2]:# and item[1] >= 4:

?????????????????????????lowercase, uppercase, number, other = strhandle(item[1])

?????????????????????????if (lowercase > 0 and uppercase > 0 and number > 0) or (

?????????????????????????????????????????????lowercase > 0 and uppercase > 0 and other > 0) or (

?????????????????????????????????????????????number > 0 and other > 0 and lowercase > 0) or (

?????????????????????????????????????????????number > 0 and other > 0 and uppercase > 0):

?????????????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????????????self.assertIn('兩次輸入的新密碼不同!', text, ' 兩次輸入的新密碼不同!')

?????????????????????else:

?????????????????????????print('test value incorrect! please check it')

?????????????????elif item[0] == '' or item[1] =='' or item[2] =='': # 輸入項(xiàng)為空校驗(yàn)

?????????????????????text = menu.errorDialog(menu.closeBtn)

?????????????????????self.assertIn('該輸入項(xiàng)的值不能為空!', text, ' 該輸入項(xiàng)的值不能為空!')? # 所有密碼均為空時(shí)斷言提示信息

?????????????else:

?????????????????self.assertTrue(menu.isElementExist(menu.errMessage), 'error fram not exist, please check the test value or file bug')

??

?if __name__=='__main__':

?????pass

10.RunTc.py(執(zhí)行測(cè)試用例)

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

#! user/bin/python

'''

Code description:auto run test case

Create time:

Developer:

'''

import unittest

import time

from BeautifulReport import BeautifulReport

from retail.config.conf import *

from retail.test_case.models.testreport import testreport

# TODO : will be use jenkins continuous intergration teachnology manage the auto project

if __name__ == '__main__':

????# currTime = time.strftime('%Y-%m-%d %H_%M_%S')

????# filename = currTime + '.html'

????# # 第一種測(cè)試報(bào)告

????# test_suite = unittest.defaultTestLoader.discover(tcPath, pattern='*Tc.py')

????# result = BeautifulReport(test_suite)

????# result.report(filename= filename, description='test report', log_path=reportPath)

????# # 第二種測(cè)試報(bào)告

????runner, fp, fileName = testreport()

????test_suite = unittest.defaultTestLoader.discover(tcPath, pattern='LoginTc.py')

????runner.run(test_suite)

????fp.close()

11.備注

from BeautifulReport import BeautifulReport 這個(gè)報(bào)告需要自己網(wǎng)上找一下(很多類似的測(cè)試報(bào)告源碼,不一定非使用本案例中的報(bào)告模板)

12.輸出結(jié)果展示

1.創(chuàng)建規(guī)則失敗時(shí)截圖

?Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師

2.登錄成功截圖

?Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師

3.用例執(zhí)行日志

?Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師

4.測(cè)試報(bào)告

Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師

?現(xiàn)在我也找了很多測(cè)試的朋友,做了一個(gè)分享技術(shù)的交流群,共享了很多我們收集的技術(shù)文檔和視頻教程。
如果你不想再體驗(yàn)自學(xué)時(shí)找不到資源,沒(méi)人解答問(wèn)題,堅(jiān)持幾天便放棄的感受
可以加入我們一起交流。而且還有很多在自動(dòng)化,性能,安全,測(cè)試開(kāi)發(fā)等等方面有一定建樹(shù)的技術(shù)大牛
分享他們的經(jīng)驗(yàn),還會(huì)分享很多直播講座和技術(shù)沙龍
可以免費(fèi)學(xué)習(xí)!劃重點(diǎn)!開(kāi)源的?。?!
qq群號(hào):485187702【暗號(hào):csdn11】

最后感謝每一個(gè)認(rèn)真閱讀我文章的人,看著粉絲一路的上漲和關(guān)注,禮尚往來(lái)總是要有的,雖然不是什么很值錢的東西,如果你用得到的話可以直接拿走!?希望能幫助到你!【100%無(wú)套路免費(fèi)領(lǐng)取】

Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師

Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄,selenium,測(cè)試工具,軟件測(cè)試,程序員,接口測(cè)試,自動(dòng)化測(cè)試,測(cè)試工程師文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-765497.html

到了這里,關(guān)于Selenium UI自動(dòng)化實(shí)戰(zhàn)過(guò)程記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Selenium UI自動(dòng)化測(cè)試入門(mén)

    Selenium UI自動(dòng)化測(cè)試入門(mén)

    1.先下載Pycharm編輯器, 網(wǎng)站:下載地址 2.安裝python環(huán)境包 地址:Download Python | Python.org ? ?安裝的時(shí)候記住勾選自動(dòng)配置環(huán)境變量 3.在pycharm中配置python執(zhí)行器路徑 ? 4.安裝selenium庫(kù) pip install selenium==4.1.1 ?查看當(dāng)前selenium版本 按住ctrl+鼠標(biāo)左鍵點(diǎn)擊 ?顯示版本號(hào) 5.安裝chromdriv

    2024年02月09日
    瀏覽(26)
  • 為什么UI自動(dòng)化難做?—— 關(guān)于Selenium UI自動(dòng)化的思考

    為什么UI自動(dòng)化難做?—— 關(guān)于Selenium UI自動(dòng)化的思考

    在快速迭代的產(chǎn)品、團(tuán)隊(duì)中,UI自動(dòng)化通常是一件看似美好,實(shí)際“雞肋”(甚至絕大部分連雞肋都算不上)的工具。原因不外乎以下幾點(diǎn): 通常只是聽(tīng)說(shuō)過(guò),就想去搞UI自動(dòng)化的團(tuán)隊(duì),心里都認(rèn)為「UI自動(dòng)化」等于「減少人工 提高效率」,這固然沒(méi)什么大錯(cuò),但是他們也會(huì)

    2024年02月03日
    瀏覽(20)
  • Selenium自動(dòng)化測(cè)試實(shí)戰(zhàn)之自動(dòng)化測(cè)試基礎(chǔ)

    Selenium自動(dòng)化測(cè)試實(shí)戰(zhàn)之自動(dòng)化測(cè)試基礎(chǔ)

    自動(dòng)化測(cè)試概念 是把以人為驅(qū)動(dòng)的測(cè)試轉(zhuǎn)化為機(jī)器執(zhí)行的一種過(guò)程,它是一種以程序測(cè)試程序的過(guò)程。 自動(dòng)化只是測(cè)試方式,跟測(cè)試階段無(wú)關(guān)。 可以把任何測(cè)試工作寫(xiě)一個(gè)程序自動(dòng)化實(shí)現(xiàn)都可以稱為自動(dòng)化測(cè)試。 selenium自動(dòng)化測(cè)試: 2023最新的Selenium自動(dòng)化測(cè)試實(shí)戰(zhàn),沒(méi)有比

    2024年02月13日
    瀏覽(27)
  • selenium 自動(dòng)化測(cè)試:如何搭建自動(dòng)化測(cè)試環(huán)境,搭建環(huán)境過(guò)程應(yīng)該注意的問(wèn)題

    selenium 自動(dòng)化測(cè)試:如何搭建自動(dòng)化測(cè)試環(huán)境,搭建環(huán)境過(guò)程應(yīng)該注意的問(wèn)題

    最近也有很多人私下問(wèn)我,selenium學(xué)習(xí)難嗎,基礎(chǔ)入門(mén)的學(xué)習(xí)內(nèi)容很多是3以前的版本資料,對(duì)于有基礎(chǔ)的人來(lái)說(shuō),3到4的差別雖然有,但是不足以影響自己,但是對(duì)于沒(méi)有學(xué)過(guò)的人來(lái)說(shuō),通過(guò)資料再到自己寫(xiě)的代碼,發(fā)現(xiàn)有些東西沒(méi)有,有些方法又不相同,導(dǎo)致腳本不能運(yùn)行

    2024年02月10日
    瀏覽(24)
  • python+selenium實(shí)現(xiàn)UI自動(dòng)化(一)

    python+selenium實(shí)現(xiàn)UI自動(dòng)化(一)

    selenium官方網(wǎng)站 selenium ide 錄制工具。 火狐/google/edge插件 selenium webdriver ? 結(jié)合代碼來(lái)編寫(xiě)自動(dòng)化用例。提供很多在瀏覽器上的操作的api,本文主要記錄此項(xiàng)的學(xué)習(xí)過(guò)程 selenium grid ? 分布式。火狐/google/edge上同時(shí)運(yùn)行。把所有用例拆分到多設(shè)備上運(yùn)行,運(yùn)行效率更高,更快。

    2023年04月24日
    瀏覽(20)
  • selenium-基于UI的自動(dòng)化測(cè)試框架

    selenium-基于UI的自動(dòng)化測(cè)試框架

    ??自動(dòng)化測(cè)試是指軟件測(cè)試的自動(dòng)化,在預(yù)設(shè)狀態(tài)下運(yùn)行應(yīng)用程序或者系統(tǒng),預(yù)設(shè)條件包括正常和異常,最后評(píng)估運(yùn)行結(jié)果,將人為驅(qū)動(dòng)的測(cè)試行為轉(zhuǎn)化為機(jī)器執(zhí)行的過(guò)程 ??自動(dòng)化測(cè)試包括UI自動(dòng)化、接口自動(dòng)化、單元測(cè)試自動(dòng)化。按照這個(gè)金字塔模型來(lái)進(jìn)行自動(dòng)化測(cè)試

    2024年02月05日
    瀏覽(39)
  • python+selenium封裝UI自動(dòng)化框架

    python+selenium封裝UI自動(dòng)化框架

    seleinum框架 框架的思想: 解決我們測(cè)試過(guò)程中的問(wèn)題:大量的重復(fù)步驟,用自動(dòng)化來(lái)實(shí)現(xiàn) 1)配置和程序的分離 2)測(cè)試數(shù)據(jù)和程序的分離 3)不懂編程的人員可以方便使用:使用的時(shí)候不需要寫(xiě)程序 4)有日志功能,實(shí)現(xiàn)無(wú)人值守 5)自動(dòng)發(fā)報(bào)告 6)框架中不要有重復(fù)的代碼,

    2024年02月09日
    瀏覽(22)
  • Selenium 自動(dòng)化 | 案例實(shí)戰(zhàn)篇

    Selenium 自動(dòng)化 | 案例實(shí)戰(zhàn)篇

    Chrome DevTools 是一組直接內(nèi)置在基于 Chromium 的瀏覽器(如 Chrome、Opera 和 Microsoft Edge)中的工具,用于幫助開(kāi)發(fā)人員調(diào)試和研究網(wǎng)站。 借助 Chrome DevTools,開(kāi)發(fā)人員可以更深入地訪問(wèn)網(wǎng)站,并能夠: 檢查 DOM 中的元素 即時(shí)編輯元素和 CSS 檢查和監(jiān)控網(wǎng)站的性能 模擬用戶的地理位

    2024年02月13日
    瀏覽(20)
  • selenium自動(dòng)化登錄(實(shí)戰(zhàn)解析)

    selenium自動(dòng)化登錄(實(shí)戰(zhàn)解析)

    目錄 1.純英文驗(yàn)證碼 1.首先需要了解運(yùn)行所需要的模塊 2.獲取我們的目標(biāo)地址鏈接 3.進(jìn)入古詩(shī)詞首頁(yè)面,找到驗(yàn)證碼的標(biāo)簽,獲取并且保存 4.調(diào)用超級(jí)鷹打碼平臺(tái) 5.調(diào)用超級(jí)鷹內(nèi)的方法 6.輸入賬號(hào)密碼 7.模擬登陸需要用cookie保持登陸狀態(tài) 相信有很多新手小白都跟我遇到一樣的

    2024年02月15日
    瀏覽(25)
  • Selenium+Python自動(dòng)化腳本環(huán)境搭建的全過(guò)程

    Selenium+Python自動(dòng)化腳本環(huán)境搭建的全過(guò)程

    * 本文僅介紹環(huán)境的搭建,不包含任何腳本編寫(xiě)教程。 先整體說(shuō)一下需要用到工具 1、Python環(huán)境(包括pip) 2、谷歌瀏覽器(包括對(duì)應(yīng)的WebDriver) 詳細(xì)步驟: 1、下載安裝包 Python Releases for Windows | Python.org ? 下載完成過(guò)后,打開(kāi)進(jìn)行安裝, 先把下面的add path打鉤 ,然后一直下

    2024年01月17日
    瀏覽(25)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包