• 测试工具介绍


    1. Python + selenium 

    这个是大家最初的选择, 但是个人认为不是太好用. 

    参考博客: https://www.cnblogs.com/xiaxiaoxu/p/8909622.html

    https://www.cnblogs.com/hanxiaobei/p/6108677.html

    https://www.cnblogs.com/eternal1025/p/8880245.html

    https://www.cnblogs.com/MrCandy/p/4230031.html

    https://blog.csdn.net/qq_34062683/article/details/78063035

    这里贴出个人写的测试代码, 是在自己搭建的服务器上运行的, 代码建供参考, 学习里面的内容才是最重要的.

    个人是使用python3.7.3的版本去测试, 64位电脑, 4G的内存, 工具使用visual studio code编辑器.

    详细代码可以去我的github下载: https://github.com/xumgit/TestScript/tree/master/python/pythonOneProject

    目录结构如下:

    个人总结: 
    1. 运用python3的多线程发送批量数据, 验证服务器的性能等很多的测试
    2. 用selenium对各种组件的选择/判断等相关的操作
    3. python + selenium中三种等待需要合理的使用

    #
    coding=utf-8 from selenium import webdriver from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By import requests import json import time import TVDiscovery import ReadForUpgrade import UpgradeInProgress import NotInUpgradeMode import datetime import os import math import CommonConstant import MultiThread def getCurentTime(): currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) return currentTime def getDriver(absolutionChromedriverPath): # driver = webdriver.Firefox() //打开Firefox浏览器 # driver = webdriver.Ie() //打开IE浏览器 driver = webdriver.Chrome(executable_path=absolutionChromedriverPath) return driver def openCmndPage(dr): # chromedriver download url: http://chromedriver.storage.googleapis.com/index.html request_url = "http://localhost:8080/cas/login?service=http%3A%2F%2Flocalhost%3A8080%2FSmartInstall%2Flogin%2Fcas" response = dr.get(request_url) #statusCode = response.status_code #responseText = response.text #print("response:" + response + ",responseText:" + responseText) dr.maximize_window() dr.implicitly_wait(5) title = dr.title #print("title:" + title) currentUrl = dr.current_url #print("currentUrl:" + currentUrl) def logIn(dr): dr.find_element_by_id('username').send_keys('admin') dr.find_element_by_id('password').send_keys('tpvision') dr.find_element_by_css_selector("input[name='submit']").click() def gotoFile_clone_tab(dr): files_parentObj = dr.find_element_by_xpath("//a[@id='nav_files']/..") class_files = files_parentObj.get_attribute("class") if ('active' != class_files) : files_parentObj.click() time.sleep(2) clone_parentObj = dr.find_element_by_xpath("//a[@data-table='tabs_clone']/..") class_files_clone = clone_parentObj.get_attribute("class") if ('active' != class_files_clone) : clone_parentObj.click() time.sleep(1) def uploadFile(dr, filePath, uploadFileKey): exist = checkUploadFileExist(dr, uploadFileKey) if exist > 0: print("had exist uploaded clone package") else: absolutionFilePath = os.path.abspath(filePath) #print("absolutionFilePath:" + absolutionFilePath) inputObj = dr.find_element_by_css_selector("input[name='uploadedfile']").send_keys(absolutionFilePath) dr.implicitly_wait(60) def fileClonePageCycle(dr, uploadFileKey): currentActivePage = dr.find_element_by_css_selector("#grid-clone-footer ul.pagination li.active") #print("ulObj:" + str(ulObj.text)) #currentActivePage = ulObj.find_element_by_xpath("//li[contains(@class, 'active')]") pageText = currentActivePage.text if (1 != int(pageText)): dr.find_element_by_css_selector("#grid-clone-footer ul.pagination li.page-1 a").click() liListObj = dr.find_elements_by_xpath("//div[@id='grid-clone-footer']/div/div/ul/li[starts-with(@class, 'page-')]") #liListObj = dr.find_elements_by_css_selector("#grid-clone-footer ul.pagination > li") liListLen = len(liListObj) for index in range(0, liListLen): if index != 0: pageIndex = index + 1 dr.find_element_by_css_selector("#grid-clone-footer ul.pagination li.page-" + str(pageIndex) + " a").click() time.sleep(3) deleteUploadFile(dr, uploadFileKey) def deleteUploadFile(dr, uploadFileKey): count = getHaveUploadFileNameCount(dr, uploadFileKey) if (count > 0): for index in range(0, count): time.sleep(1) hitIndex = getHitIndex(dr, uploadFileKey) if (hitIndex > 0): aListObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr:nth-of-type(" + str(hitIndex) + ") > td:nth-of-type(12) > a") aListLen = len(aListObj) for indexJ in range(0, aListLen): idValue = aListObj[indexJ].get_attribute("id") if idValue.find("dele_") > -1 : aListObj[indexJ].click() time.sleep(1) dr.find_element_by_id('deleteCloneConfirmBtn').click() time.sleep(2) break # trListObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr") # #listObj = tBodyObj.find_elements_by_css_selector("tr > td:nth-of-type(2) > input") # trListlen = len(trListObj) # for index in range(0, trListlen): # trIndex = index + 1 # listObj = dr.find_element_by_css_selector("#grid-clone > tbody > tr:nth-of-type(" + str(trIndex) + ") > td:nth-of-type(2) > input") # cloneDataValue = listObj.get_attribute("value") # if (cloneDataValue.find(uploadFileKey) > -1): # aListObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr:nth-of-type(" + str(trIndex) + ") > td:nth-of-type(12) > a") # aListLen = len(aListObj) # for indexJ in range(0, aListLen): # idValue = aListObj[indexJ].get_attribute("id") # if idValue.find("dele_") > -1 : # aListObj[indexJ].click() # #tdListObj.find_element_by_xpath("//a[contains(@id, 'dele_')]") # #tdListObj.find_element_by_xpath("//a[ends-with(@id, 'dele_')]") # #tdListObj.find_element_by_xpath("//a[starts-with(@id, 'dele_')]").click() # time.sleep(1) # dr.find_element_by_id('deleteCloneConfirmBtn').click() # time.sleep(2) # break # #aListObj = trListObj[index].find_elements_by_css_selector("td:nth-of-type(12) > a") # #aListLen = len(aListObj) # #for indexJ in range(0, aListLen): # # nameValue = aListObj[indexJ].get_attribute("id") # #break # return 1 def getHaveUploadFileNameCount(dr, uploadFileKey): count = 0 trListObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr") #listObj = tBodyObj.find_elements_by_css_selector("tr > td:nth-of-type(2) > input") trListlen = len(trListObj) for index in range(0, trListlen): trIndex = index + 1 listObj = dr.find_element_by_css_selector("#grid-clone > tbody > tr:nth-of-type(" + str(trIndex) + ") > td:nth-of-type(2) > input") cloneDataValue = listObj.get_attribute("value") if (cloneDataValue.find(uploadFileKey) > -1): count = count + 1 return count def getHitIndex(dr, uploadFileKey): hitIndex = -1 trListObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr") #listObj = tBodyObj.find_elements_by_css_selector("tr > td:nth-of-type(2) > input") trListlen = len(trListObj) for index in range(0, trListlen): trIndex = index + 1 listObj = dr.find_element_by_css_selector("#grid-clone > tbody > tr:nth-of-type(" + str(trIndex) + ") > td:nth-of-type(2) > input") cloneDataValue = listObj.get_attribute("value") if (cloneDataValue.find(uploadFileKey) > -1): hitIndex = trIndex break return hitIndex def checkUploadFileExist(dr, uploadFileKey): exist = 0 listObj = dr.find_elements_by_css_selector("#grid-clone > tbody > tr > td:nth-of-type(2) > input") listlen = len(listObj) for index in range(0, listlen): cloneDataValue = listObj[index].get_attribute("value") if (cloneDataValue.find(uploadFileKey) > -1): exist = 1 break return exist def gotoTVS_tvs_tab(dr): #print("currentUrl:" + dr.current_url) tvs_parentObj = dr.find_element_by_xpath("//a[@id='nav_tvs']/..") class_tvs = tvs_parentObj.get_attribute("class") #print('class_tvs:' + class_tvs + ",text:" + tvs_parentObj.text) if ('active' != class_tvs) : tvs_parentObj.click() time.sleep(2) #print("currentUrl:" + dr.current_url) devices_parentObj = dr.find_element_by_xpath("//a[@data-table='tabs-devices']/..") class_tvs_tvs = devices_parentObj.get_attribute("class") #print('class_tvs_tvs:' + class_tvs_tvs + ",text:" + devices_parentObj.text) if ('active' != class_tvs_tvs) : devices_parentObj.click() time.sleep(1) def changePageSize(dr, pageSize): currentPageSize = dr.find_element_by_css_selector('#grid_devices-header button.dropdown-toggle span.dropdown-text').text if (pageSize == int(currentPageSize)): pass else: toggleBtn = dr.find_element_by_css_selector('#grid_devices-header button.dropdown-toggle') toggleBtn.click() time.sleep(1) liaList = dr.find_elements_by_css_selector('#grid_devices-header ul.dropdown-menu:nth-of-type(1) > li > a') liaListLen = len(liaList) for index in range(0, liaListLen): if (pageSize == int(liaList[index].text)): liaList[index].click() break time.sleep(1) def checkWhetherRefresh(dr, checkType, conditionValue): refreshFlag = 0 commonConstant = CommonConstant.CommonConstant() trListobj = dr.find_elements_by_css_selector("#tvsBody > tr") trLen = len(trListobj) if (checkType.find(commonConstant.getTVDiscovery()) > -1): for indexI in range(0, trLen): swText = trListobj[indexI].find_element_by_id("tv_SwDiv").text if conditionValue == swText: refreshFlag = 1 break elif (checkType.find(commonConstant.getAssignCloneData()) > -1) or (checkType.find(commonConstant.getUpgradeInProgress()) > -1) or (checkType.find(commonConstant.getNotInUpgradeMode()) > -1): for indexJ in range(0, trLen): colorValue = trListobj[indexJ].find_element_by_id("tv_CloneDiv").value_of_css_property("color") if conditionValue != colorValue: refreshFlag = 1 break print(checkType + ",refreshFlag:" + str(refreshFlag)) return refreshFlag def selectAllTv(dr): selectAllTvCheck = dr.find_element_by_css_selector("input[name='select']") isSelected = selectAllTvCheck.is_selected() print("isSelected:" + str(isSelected)) if isSelected: pass else: selectAllTvCheck.click() time.sleep(1) def assignClonePackage(dr, seletCloneType, uploadFileKey): dr.find_element_by_id('assign_select').click() time.sleep(1) liList = dr.find_elements_by_css_selector('#assign_select > ul > li') listlen = len(liList) for index in range(0, listlen): cloneType = liList[index].text if (cloneType.find(seletCloneType) > -1) : liList[index].click() break time.sleep(2) tdList = dr.find_elements_by_css_selector('#assignSelectRows > tr > td:nth-of-type(1)') tdListlen = len(tdList) for indexJ in range(0, tdListlen): cloneValue = tdList[indexJ].text if (cloneValue.find(uploadFileKey) > -1) : tdList[indexJ].click() break time.sleep(1) def getAssignItemIdentifier(dr): identifier = "10/06/2019:15:05" firstTvObj = dr.find_element_by_css_selector('#tvsBody > tr:nth-of-type(1) > td:nth-of-type(10) > div') sicloneidentValue = firstTvObj.get_attribute("sicloneident") try: time_temp = time.strptime(sicloneidentValue, "%Y/%m/%d-%H:%M:%S") identifier = time.strftime("%d/%m/%Y:%H:%M", time_temp) print("identifier:" + identifier) except Exception as e: print("exception:" + e) return identifier def checkCloneColor(dr, logType, color): tvsList = dr.find_elements_by_css_selector('#tvsBody > tr > td:nth-of-type(10) > div') tvListLen = len(tvsList) for index in range(0, tvListLen): colorValue = tvsList[index].value_of_css_property("color") if (color == colorValue): pass else: startallidValue = tvsList[index].get_attribute("startallid") errTvObj = dr.find_element_by_css_selector("#tvsBody > tr[data-row-id='" + startallidValue + "'] > td:nth-of-type(8) > div") print(logType + ",color not match, tv ip address:" + errTvObj.text) def forceUpgradeItem(dr, forceBtnText): forceUpgradeBtn = dr.find_element_by_id('allBtn') if ((forceUpgradeBtn.text).find(forceBtnText) > -1): forceUpgradeBtn.click() else: print("force upgrade error") time.sleep(1) def mainFunction(): print("startTime:" + getCurentTime()) starttime = datetime.datetime.now() commonConstant = CommonConstant.CommonConstant() absolutionChromedriverPath = os.path.abspath(commonConstant.getAbsolutionChromedriverPath()) dr = getDriver(absolutionChromedriverPath) generateTvsCount = commonConstant.getGenerateTvsCount() groupTvs = commonConstant.getGroupTvs() divide = math.floor(generateTvsCount / groupTvs) remainder = generateTvsCount % groupTvs if (remainder > 0): divide = divide + 1 uploadFilePath = commonConstant.getUploadFilePath() uploadFileKey = commonConstant.getUploadFileKey() selectCloneType = commonConstant.getSelectCloneType() pageSize = commonConstant.getPageSize() forceBtnText = commonConstant.getForceBtnText() blueColor = commonConstant.getBlueColor() orangeColor = commonConstant.getOrangeColor() greenColor = commonConstant.getGreenColor() openCmndPage(dr) dr.implicitly_wait(3) logIn(dr) dr.implicitly_wait(3) gotoFile_clone_tab(dr) time.sleep(3) uploadFile(dr, uploadFilePath, uploadFileKey) time.sleep(3) gotoTVS_tvs_tab(dr) time.sleep(3) changePageSize(dr, pageSize) time.sleep(1) MultiThread.mulThreadSendTypeData(commonConstant.getTVDiscovery(), divide, remainder, groupTvs) time.sleep(1) MultiThread.mulThreadSendTypeData(commonConstant.getReadForUpgrade(), divide, remainder, groupTvs) time.sleep(5) # tvDiscovery = TVDiscovery.TVDiscovery(generateTvsCount) # tvDiscovery.genarateManyTvs() # time.sleep(1) if checkWhetherRefresh(dr, commonConstant.getTVDiscovery(), commonConstant.getNone()) > 0: dr.refresh() dr.implicitly_wait(30) print("==========generate tv success==========") time.sleep(5) selectAllTv(dr) time.sleep(1) assignClonePackage(dr, selectCloneType, uploadFileKey) time.sleep(1) #div.toast-container > div.toast-item-wrapper WebDriverWait(dr, 60).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, ".toast-item-wrapper"))) time.sleep(3) assignIdentifier = getAssignItemIdentifier(dr) time.sleep(1) if checkWhetherRefresh(dr, commonConstant.getAssignCloneData(), blueColor) > 0: dr.refresh() dr.implicitly_wait(30) checkCloneColor(dr, commonConstant.getAssignCloneData(), blueColor) print("==========assign Clone package success==========") time.sleep(1) forceUpgradeItem(dr, forceBtnText) #print("==========click upgrade success==========") MultiThread.mulThreadSendTypeData(commonConstant.getUpgradeInProgress(), divide, remainder, groupTvs) time.sleep(5) # upgradeInProgress = UpgradeInProgress.UpgradeInProgress(generateTvsCount) # upgradeInProgress.sendUpgradeInProgressData() # time.sleep(1) if checkWhetherRefresh(dr, commonConstant.getUpgradeInProgress(), orangeColor) > 0: dr.refresh() dr.implicitly_wait(30) checkCloneColor(dr, commonConstant.getUpgradeInProgress(), orangeColor) print("==========send upgradeInProgress success==========") time.sleep(10) upgradeIdentifier = {"TVChannelList": assignIdentifier} MultiThread.mulThreadSendTypeData(commonConstant.getNotInUpgradeMode(), divide, remainder, groupTvs, upgradeIdentifier) time.sleep(5) # notInUpgradeMode = NotInUpgradeMode.NotInUpgradeMode(generateTvsCount, upgradeIdentifier) # notInUpgradeMode.sendNotInUpgradeModeData() # time.sleep(1) if checkWhetherRefresh(dr, commonConstant.getNotInUpgradeMode(), greenColor) > 0: dr.refresh() dr.implicitly_wait(30) checkCloneColor(dr, commonConstant.getNotInUpgradeMode(), greenColor) print("==========send NotInUpgradeMode success==========") time.sleep(2) gotoFile_clone_tab(dr) time.sleep(2) fileClonePageCycle(dr, uploadFileKey) #deleteUploadFile(dr, uploadFileKey) print("==========delete Clone Package success==========") endtime = datetime.datetime.now() consumerTime = (endtime - starttime).seconds print ("total consumer time:" + str(consumerTime) + " seconds") time.sleep(10) print("endTime:" + getCurentTime()) dr.quit()

    2. Katalon

    地址: https://docs.katalon.com/katalon-studio/docs/index.html

    这是国外的一个测试工具, 一键安装, 省去了大量的工作, 非常的方便.

    这个测试工具非常的合适那些经常写java代码的人去写测试脚本, 这款不仅可以测试网页, 同时也可以测试手机(包括android和ios的平板).

    3. Cypress

    地址: https://docs.cypress.io/guides/overview/why-cypress.html

    这也是国外的一个测试工具, 使用nodejs去安装, 测试, 也很方便.

    这个测试工具是端到端(e2e)的web页面测试, 最近一段时间一直在用这个去写测试脚本.

    这里给出cypress写的测试代码, 按照上面的cypress地址构建项目, 如下:

    每个目录代表什么意思,请详细查看cypress官网的介绍, 就是上面给出的网址.

     下面实例仅供参考, 我是在自己搭建的本地服务(tomcat)上去运行的, 也可以不用本地服务, 关键看你需要什么样的测试.

     不要直接复制粘贴代码(我是在本地服务去上运行的), 学习里面的内容才是重要的

    详细的代码可以去我的git下载: https://github.com/xumgit/TestScript/tree/master/cypress/testProjectOne

    context('Unit Test', () => {
    
      before(function() {
            cy.log('before => runs once before all tests in the block')
      })
    
      after(function() {
            cy.log('after => runs once after all tests in the block')
      })
    
      beforeEach(function() {
            cy.log('beforeEach => runs before each test in the block')
          cy.fixture('tvdata.json').as('TVData')
      })
    
      afterEach(function() {
            cy.log('afterEach => runs after each test in the block')
      })
    
      // function numsExpectedToEq (arr, expected) {
      //   // loop through the array of nums and make
      //   // sure they equal what is expected
      //   arr.forEach((num) => {
      //       expect(fizzbuzz(num)).to.eq(expected)
      //   })
      // }
    
      const commonRequest = {
            method: 'POST',
            form: false,
            headers: {
                "Authorization": "whateverYouNeedForAuthentication",
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
            url: null,
            body: null
      }
    
      function changeData(data, changeDataObj) {       
            if (null == changeDataObj) {
                cy.log("changeDataObj is null")
                return data
            }
            if (null == data) {
                cy.log("data is null")
                return data
            }
            let notInUpgradeModeDataObj = data.NotInUpgradeModeData
            if (null == notInUpgradeModeDataObj) {
                cy.log("notInUpgradeModeDataObj is null")
                return data
            }
            let commandDetailsObj = notInUpgradeModeDataObj.CommandDetails
            if (null == commandDetailsObj) {
                cy.log("commandDetailsObj is null")
                return data
            }
            let ipCloneParametersObj = commandDetailsObj.IPCloneParameters
            if (null == ipCloneParametersObj) {
                cy.log("ipCloneParametersObj is null")
                return data
            }
            let cloneSessionStatusObj = ipCloneParametersObj.CloneSessionStatus
            if (null == cloneSessionStatusObj) {
                cy.log("cloneSessionStatusObj is null")
                return data
            }
            let cloneItemStatusArrObj = cloneSessionStatusObj.CloneItemStatus
            if (null == cloneItemStatusArrObj) {
                cy.log("cloneItemStatusArrObj is null")
                return data
            }
            let arrLen = cloneItemStatusArrObj.length
            for(let i = 0; i < arrLen; i++) {
                let cloneItemDetailsObj = cloneItemStatusArrObj[i].CloneItemDetails
                let cloneItemName = cloneItemDetailsObj.CloneItemName
                if (null != cloneItemName && "" != cloneItemName 
                        && changeDataObj.hasOwnProperty(cloneItemName)) {
                    cloneItemDetailsObj.CloneItemVersionNo = changeDataObj[cloneItemName]
                }
            }
            return data
      }
    
      function one_Login_CMND_page() {
            cy.log("Login CMND page")
            cy.visit('/')  // 访问页面, 地址在cypress.json中的baseUrl
            //cy.url().should("include", "/SmartInstall")       //验证是否含有指定地址
            cy.wait(1000)
            cy.get('#username', {timeout: 5000}).type("admin")
            cy.get('#password', {timeout: 5000}).type("tpvision")
            cy.wait(1000)
            cy.get('.btn').click()
            cy.wait(3000)
      }
    
      function two_Navigation_to_TVS_tv_page() {
            cy.log("Navigation to TVS_tv page")
            cy.wait(3000)
            cy.get('#nav_tvs')
                .as('mainNaviTVs')
                //.parent('li')
                //.should('not.have.class', 'active')
                .then(($parentDom) => {
                    cy.wait(3000)
                    if (!$parentDom.parent().hasClass('active')) {
                        cy.get('@mainNaviTVs').click()
                        cy.wait(3000)
                    }
                })
    
            cy.wait(3000)
    
            cy.get('a[data-table=tabs-devices]')
                .as('mainNaviTVs_tvs')
                //.parent("li")
                //.should('not.have.class', 'active')
                .should('be.visible')
                .then(($parentD) => {
                    cy.wait(3000)
                    if (!$parentD.parent().hasClass('active')) {
                    cy.get('@mainNaviTVs_tvs').click()
                    cy.wait(3000)
                    }
                })
      }
    
      function three_Send_TVDiscovery_data() {
            cy.log("Send TVDiscovery, generate a emulator tv")
            cy.get('@TVData').then((tvData) => {
                cy.wait(3000)
                //console.log("TVDiscoveryData:" + tvData.TVDiscoveryData);
                commonRequest.url = tvData.WebServicesUrl
                commonRequest.body = JSON.stringify(tvData.TVDiscoveryData);
                cy.request(commonRequest).then((resp)=>{
                    //console.log("resp:" + JSON.stringify(resp));
                    cy.log("send TVDiscovery status:" + resp.status)
                    cy.wait(10000)
                    let isRefreshPage = true
                    cy.get("#tvsBody > tr")
                    .each(($tr, index, $arrList) => {
                        let tvUniqueID = $tr.attr("data-row-id")
                        if (tvUniqueID == tvData.TVUniqueID) {
                            isRefreshPage = false
                        }
                    })
                    .then(() => {
                        if (isRefreshPage) {
                            cy.reload()
                        }
                    })             
                })
            })
      }
    
      function four_Send_IPClonservice_data() {
            cy.log("Send IPClonservice, show Firmware version")
            cy.get('@TVData').then((tvData) => {
                cy.wait(3000)
                commonRequest.url = tvData.WebServicesUrl
                commonRequest.body = JSON.stringify(tvData.ReadyForUpgradeData)
                cy.request(commonRequest).then((res) => {
                    cy.log("send IPClonservice status:" + res.status)
                    cy.wait(3000)
                });
            })
      }
    
      function five_Select_TV() {
            cy.log("Select TV")
            cy.wait(3000)
            cy.get('@TVData').then((tvData) => {
                cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                    .should('exist')
                    .then(($targetDom) => {
                        cy.wait(3000)
                        cy.get("#tvsBody > tr")
                          .each(($tr, index, $arrList) => {
                             let tvUniqueID = $tr.attr("data-row-id")
                             if (tvUniqueID != tvData.TVUniqueID) {
                                 if ($tr.hasClass('active')) {
                                    $tr.find("input[name=select]").click()
                                 }
                             } else {
                                if (!$tr.hasClass('active')) {
                                    $tr.find("input[name=select]").click()
                                 }
                             }
                          })
                    })
            })
      }
    
      function six_Assign_Clone_data() {
            cy.log("Assign Clone data, then check blue color")
            cy.wait(3000)
            cy.get('@TVData').then((tvData) => {
                cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                    .should('exist')
                    .then(() => {
                        cy.wait(3000)
                        cy.get("#assign_select")
                        .click()
                        .then(($dom) => {
                            cy.wait(1000)
                            $dom.find("ul li:eq(3)").click()
                            cy.wait(3000)
                            cy.get("#assignSelectRows > tr")
                                //.its('length')
                                //.should('be.gt', 1)
                                //.contains('CypressTestCloneData')
                                //.click()
                                .each(($tr, index, $arrList) => {
                                    let selectText = $tr.find("td").eq(0).text()
                                    cy.log("text_" + index + ":" + selectText)
                                    if (selectText.indexOf('CypressTestCloneData') > -1) {
                                        cy.log("CloneData select success")
                                        $tr.click()                              
                                    }
                                })
                                .then(() => {
                                    cy.wait(10000)
                                    cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                                    .find("#tv_CloneDiv")
                                    .should('have.css', 'color', tvData.BlueColor)
                                })
                        })
                    })
            })
      }
    
      function seven_Click_Upgrade_button() {
            cy.log("Click Upgrade button, means ready to upgrade")
            cy.wait(3000)
            cy.get('@TVData').then((tvData)=>{
                cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                .should('exist')
                .then(() => {
                        cy.wait(3000)
                        cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                        .should('exist')
                        .find("span.glyphicon-refresh")
                        .should('exist')
                        .click()
                    })
            })
      }
    
      function eight_Emulator_TV_Response_UpgradeInprogress() {
            cy.log("Emulator TV response UpgradeInprogress, then check clone orange color")
            cy.wait(3000)
            cy.get('@TVData').then((tvData) => {
                commonRequest.url = tvData.WebServicesUrl;
                commonRequest.body = JSON.stringify(tvData.UpGradeInProgressData);
                cy.request(commonRequest).then((resp) => {
                    cy.wait(3000)
                    const responseCode = resp.status;
                    console.log("responseCode:" + responseCode);
                    if (responseCode == 200) {
                            cy.wait(1000)
                            cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                            .should('exist')
                            .find("img.hideIcon")
                            .then(($imgIcon) => {
                                cy.wait(1000)
                                if ($imgIcon.length > 0) {
                                } else {
                                    cy.reload()
                                }
                            })
                    }
                }).then(() => {
                    cy.wait(3000)
                    cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                        .should('exist')
                        .then(() => {
                            cy.wait(5000)
                            cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                            .find("#tv_CloneDiv")
                            .should('have.css', 'color', tvData.OrangeColor)
                        })
                })
            })
      }
    
      function nine_Emulator_TV_Response_NotInUpgradeMode() {
            cy.log("Emulator TV response NotInUpgradeMode, then check clone green color")
            cy.wait(3000)
            cy.get('@TVData').then((tvData) => {
                commonRequest.url = tvData.WebServicesUrl;
                let changeDataObj = {}
                changeDataObj[tvData.CloneItems["TVChannelList"]] = "04/06/2019:01:39";
                changeDataObj[tvData.CloneItems["HTVCfg.xml"]] = "04/06/2019:15:15";
                changeDataObj[tvData.CloneItems["ProfessionalAppsData"]] = "04/06/2019:15:15";
                changeDataObj[tvData.CloneItems["RoomSpecificSettings"]] = "24/08/2018:11:45";
                changeDataObj[tvData.CloneItems["Schedules"]] = "23/08/2018:10:34";
                changeDataObj[tvData.CloneItems["TVSettings"]] = "04/06/2019:13:39";
                let data = changeData(tvData, changeDataObj)
                commonRequest.body = JSON.stringify(data.NotInUpgradeModeData);
                cy.request(commonRequest).then((resp) => {
                    cy.wait(7000)
                    const responseCode = resp.status;
                    cy.log("NotInUpgradeMode responseCode:" + responseCode);
                    if (responseCode == 200) {
                        cy.wait(1000)
                        cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                        .should('exist')
                        .find("img.hideIcon")
                        .then(($imgIcon) => {
                            cy.wait(1000)
                            if ($imgIcon.length > 0) {
                                cy.reload()
                            } 
                        })
                    }
                }).then(() => {
                    cy.wait(5000)
                    cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                        .should('exist')
                        .then(() => {
                            cy.wait(5000)
                            cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                            .find("#tv_CloneDiv")
                            .should('have.css', 'color', tvData.GreenColor)
                        })
                })
            })
      }
    
      function ten_Click_Info_Dialog_button() {
            cy.log("Click info dialog button, further check upgrade info")
            cy.wait(5000)
            cy.get('@TVData').then((tvData) => {
                cy.wait(5000)
                cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                    .should('exist')
                    .find("span.glyphicon-info-sign")
                    .should('exist')
                    .click()
                    .then(() => {
                        cy.wait(2000)
                        cy.get("#TV_info").scrollTo('center')
                        cy.wait(8000)
                        .then(() => {
                            cy.get("#infoModal_ID button.close").click()
                        })
                    })
            })
      }
    
      function eleven_delete_TV() {
            cy.log("delete this tv")
            cy.wait(3000)
            cy.get('@TVData').then((tvData) => {
                cy.wait(5000)
                cy.get("#tvsBody tr[data-row-id="" + tvData.TVUniqueID + ""]")
                    .should('exist')
                    .find("span.glyphicon-trash")
                    .should('exist')
                    .click()
                    .then(() => {
                        cy.wait(2000)
                        cy.get("#tvDeleteModal #deleteTV")
                        .should("exist")
                        .click()
                    })
            })
      }
    
     // it will only this case, after all case will not execute
     // it.only('returns "fizz" when number is multiple of 3', function () {
     //   numsExpectedToEq([9, 12, 18], 'fizz')
     // })
    
      // it('returns "buzz" when number is multiple of 5', function () {
      //     numsExpectedToEq([10, 20, 25], 'buzz')
      // })
      //
      // // this case will skip
      // it.skip('returns "fizzbuzz" when number is multiple of both 3 and 5', function () {
      //     numsExpectedToEq([15, 30, 60], 'fizzbuzz')
      // })
    
      it('Clone Upgrade Success demo', () => {
          one_Login_CMND_page()
          two_Navigation_to_TVS_tv_page()
          three_Send_TVDiscovery_data()
          four_Send_IPClonservice_data()
          five_Select_TV()
          six_Assign_Clone_data()
          seven_Click_Upgrade_button()
          eight_Emulator_TV_Response_UpgradeInprogress()
          nine_Emulator_TV_Response_NotInUpgradeMode()
          ten_Click_Info_Dialog_button()
          eleven_delete_TV()
      })

    后续我会把用这个三个工具所写的测试脚本代码, 粘贴出来,

    敬请待续...

  • 相关阅读:
    关于粒子发射(CAEmitterLayer)
    自定义cell(xib)中button点击事件不能响应的情况
    xcode意外退出
    iOS开发技巧-2
    禁止UIWebView随键盘的弹起而往上滚动
    内联函数
    使用sudo apt-get出现无法解析域名的问题:“cn.archive.ubuntu.com”
    iOS进阶
    swift 中的defer
    iOS中static的作用
  • 原文地址:https://www.cnblogs.com/xumBlog/p/10991467.html
Copyright © 2020-2023  润新知