測試工具介紹

1. Python + selenium css

這個是你們最初的選擇, 可是我的認爲不是太好用. html

參考博客: http://www.javashuo.com/article/p-hzoakqdh-cg.htmljava

http://www.javashuo.com/article/p-svtdthsc-bv.htmlnode

http://www.javashuo.com/article/p-plrkpaua-mt.htmlpython

http://www.javashuo.com/article/p-qlhwbakv-q.htmlandroid

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

這裏貼出我的寫的測試代碼, 是在本身搭建的服務器上運行的, 代碼建供參考, 學習裏面的內容纔是最重要的.git

我的是使用python3.7.3的版本去測試, 64位電腦, 4G的內存, 工具使用visual studio code編輯器.github

詳細代碼能夠去個人github下載: https://github.com/xumgit/TestScript/tree/master/python/pythonOneProjectweb

目錄結構以下:

我的總結: 
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()
  })

 

後續我會把用這個三個工具所寫的測試腳本代碼, 粘貼出來,

敬請待續...

相關文章
相關標籤/搜索