Exemple #1
0
    def checkDestination(self, inputContent):
        ###############################
        #Grab imge and imgeprocessing
        self.grabAndHandleImage(r"D:\Temp\TA\Mask\WaitDestinationCheck.xml",
                                inputContent)

        for i in range(25):
            waitDoneFlag = 0
            colorResult = self.handleImage.recognizeColor([20, 35], [20, 35],
                                                          [20, 30])
            if colorResult == 1:
                MyLog.debug("Please wait!!! Wait for information")
                print "Please wait"

                #Grab imge and imgeprocessing
                self.grabAndHandleImage(
                    r"D:\Temp\TA\Mask\WaitDestinationCheck.xml", inputContent)
                time.sleep(4)

            else:
                waitDoneFlag = 1
                break

        if waitDoneFlag == 1:

            recFlag = self.loopCheckDes(620, 680, 620, 320, 20, inputContent)
            if recFlag == 0:
                self.inputC.deleteEntry()
                return recFlag

        else:
            self.passFlag = 0
            self.msg = "Failed!!! Timeout"
            MyLog.error("Failed!!! Timeout")
            print "Failed!!! Timeout"
Exemple #2
0
    def loopCheckDes(self, csX, csY, ceX, ceY, offset, inputContent):
        ##########################################
        '''
        When loopCheckDes is used csX,csY,ceX,ceY is equvilent to abt drag parameters
        The offset para is to recorrect the drag action. It is different with loopCheck
        You don't have to decide the number of loop
        '''

        MyLog.debug("Now in loopCheckDestinatons")
        print "Now we are in loopCheckDes"

        self.grabAndHandleImage(r"D:\Temp\TA\Mask\DestinationCheck.xml",
                                inputContent)
        chResult, disL, flag, rect, countNum = self.handleImage.recognizeCharacters_RC(
        )

        firstLine = chResult[0]
        print chResult[0]
        checkFlag = 1

        if countNum < 3:
            MyLog.error("Something wrong happens, please check Image " +
                        str(self.MGB.ImgFN))
            print "Something wrong happens, please check Image " + self.MGB.ImgFN
            checkFlag = 0

        while (1):
            self.touch.dragCoords(csX, csY, ceX, ceY)
            #time.sleep(1)
            self.touch.dragCoords(csX, csY, ceX, abs(csY - offset))
            time.sleep(1)

            self.grabAndHandleImage(r"D:\Temp\TA\Mask\DestinationCheck.xml",
                                    inputContent)
            chResult, disL, flag, rect, countNum = self.handleImage.recognizeCharacters_RC(
            )

            if chResult[0] == firstLine:
                break
            else:
                firstLine = chResult[0]

            if countNum < 3:
                #########################################################################
                #Here we should now in this cluster MIB2+ the destination always shows 3 result
                #So we can code like this
                #If not we should change our logic
                #########################################################################
                print "Something wrong happens, please check Image " + self.MGB.ImgFN
                checkFlag = 0

        return checkFlag
Exemple #3
0
    def initTools(self):
        ########################
        self.MGB = PyMGB.PyMGB(isVirtual=False)
        self.MGB.startGrabbing()

        #Touch screen Initialization
        self.touch = CTouchScreen()
        if self.touch.initParams(26839, 1, self.touch.CANCaseXL,
                                 self.touch.DISPLAY_TOP):
            MyLog.info("TouchScreen is OK")
            print "touchScreen is OK"
        else:
            MyLog.error("TouchScreen failed")
            print "touchScreen failed"

        self.runCases()
Exemple #4
0
    def runInputDestination(self):
        ###################################
        print self.recogCharacter["DestinationInput"]

        if self.recogCharacter["DestinationInput"]["NormalInput"]:

            for case in self.recogCharacter["DestinationInput"]["NormalInput"]:
                try:
                    #switch input method
                    if self.recogCharacter["DestinationInput"]["NormalInput"][
                            case]["Input method"] == "Free research":
                        MyLog.debug("Now run " + case + ":" +\
                                    self.recogCharacter["DestinationInput"]["NormalInput"][case]["Name"])
                        self.report.write(
                            self.row, 0,
                            self.recogCharacter["DestinationInput"]
                            ["NormalInput"][case]["Name"])
                        self.freeSearch(self.recogCharacter["DestinationInput"]
                                        ["NormalInput"][case]["Input content"])

                        if self.passFlag == 1:
                            self.report.write(self.row, 1, "Passed")
                        else:
                            self.report.write(self.row, 1, "Failed")
                            self.report.write(self.row, 2, self.msg)

                        self.row = self.row + 1
                        self.msg = ""
                        self.passFlag = 1
                    '''
                    ####################################################################################
                    If you have to use favorite or other ways to input destination, please add code here
                    ####################################################################################
                    '''
                except Exception as e:
                    MyLog.error(e.message + " recogCharacters failed")
                    self.msg = e.message + " recogCharacters failed"
                    self.report.write(self.row, 1, "Failed")
                    self.report.write(self.row, 2, self.msg)
                    self.msg = ""
                    self.passFlag = 1
                    print e.message + " recogCharacters failed"
Exemple #5
0
    def checkCharacters(self, inputContent):
        #################################
        if len(inputContent) > 1:

            self.grabAndHandleImage(r"D:\Temp\TA\Mask\CharactersCheck.xml",
                                    inputContent[0])
            chResult, disL, flag, rect = self.handleImage.recognizeCharacters()

            if disL > 0.87:
                print rect.left, rect.top, rect.right, rect.bottom
                self.touch.touchScreen(self.handleImage.mask[0] + rect.left + (rect.right-rect.left)/2,\
                                       self.handleImage.mask[1] + rect.top + (rect.bottom - rect.top)/2,\
                                       500, 1, 1)
                return 1

            else:
                recFlag = self.loopCheck(1070, 250, 300, 240, 3,
                                         inputContent[0])
                if recFlag == 0:
                    self.inputC.deleteEntry()
                    return recFlag

        else:
            #One by one check
            #Grab imge and imgeprocessing
            oneCharacter = inputContent[0].encode("utf-8")

            try:
                print oneCharacter
            except Exception as e:
                MyLog.error(e.message + " Can't print characters")
                print e.message + " Can't print characters"

            if oneCharacter.isalpha():
                #Touch OK button in the bottom screen.
                #a-z or A-Z only need to check if input is right after touch OK button
                MyLog.debug("Now input English characters")
                print "Now input English characters"
                self.inputC.touchCoords(1180, 580, 200, 2, 0)
                return 1

            elif oneCharacter.isdigit():

                #0-9 only need to check if input is right
                MyLog.debug("Now input numbers")
                print "Now input numbers"
                return 1

            else:
                #chinese characters you have to check carefully. Loopcheck if necessary

                self.grabAndHandleImage(r"D:\Temp\TA\Mask\CharactersCheck.xml",
                                        inputContent[0])
                chResult, disL, flag, rect = self.handleImage.recognizeCharacters(
                )

                if disL > 0.87:
                    print rect.left, rect.top, rect.right, rect.bottom
                    self.touch.touchScreen(self.handleImage.mask[0] + rect.left + (rect.right-rect.left)/2,\
                                           self.handleImage.mask[1] + rect.top + (rect.bottom - rect.top)/2,\
                                           500, 1, 1)
                    return 1

                else:
                    recFlag = self.loopCheck(1070, 250, 300, 240, 3,
                                             inputContent[0])
                    if recFlag == 0:
                        self.inputC.deleteEntry()
                        return recFlag
Exemple #6
0
    def freeSearch(self, inputContent):
        ##################################
        self.desInPrecondition(380, 140)

        #Input characters Initialization
        self.inputC = PyInputKeyboard.CKeyboard()

        if self.inputC.initParams(26839, 1, self.inputC.CANCaseXL, 1):
            MyLog.info("Keyinput initialization success")
            print "Keyinput initializition success"
            self.inputC.readKeyboardLayout()

        print "##############################"
        print "os.path.realpath(__file__)=%s" % os.path.realpath(__file__)

        if len(inputContent) > 1:
            self.inputC.enterString(inputContent[1], 200, 2, 0)
            #time.sleep(5)
            checkFlag = self.checkCharacters(inputContent)

            if checkFlag == 0:
                #Then you input characters one by one
                for i in range(len(inputContent[0])):
                    self.inputC.enterString(inputContent[2][i], 200, 2, 0)
                    #print inputContent[0][i]
                    detailCheckFlag = self.checkCharacters(
                        [inputContent[0][i]])
                    if detailCheckFlag == 0:
                        self.msg = "Failed!!! characters not found"
                        self.passFlag = 0
                        MyLog.error("Failed!!! characters not found")
                        print "failed!!! characters not founded"
                        break

                if detailCheckFlag != 0:
                    time.sleep(3)
                    self.grabAndHandleImage(
                        r"D:\Temp\TA\Mask\CharactersInputCheck.xml",
                        inputContent[0])
                    chResult, disL, flag, rect = self.handleImage.recognizeCharacters(
                    )

                    if disL > 0.9:
                        self.checkDestination(inputContent[0])
                    else:
                        self.msg = "Failed!!! characters not found"
                        self.passFlag = 0
                        MyLog.error("Failed!!! characters not found")
                        print "failed!!! characters not founded"
            else:
                self.checkDestination(inputContent[0])

            time.sleep(2)
            #self.inputC.deleteEntry()
        else:
            self.inputC.enterString(inputContent[0], 200, 2, 0)
            #time.sleep(5)
            #Touch OK button to input string
            self.inputC.touchCoords(1180, 580, 200, 2, 0)
            time.sleep(3)

            self.grabAndHandleImage(
                r"D:\Temp\TA\Mask\CharactersInputCheck.xml", inputContent[0])
            chResult, disL, flag, rect = self.handleImage.recognizeCharacters()

            if disL > 0.9:
                self.checkDestination(inputContent[0])
            else:
                self.msg = "Failed!!! characters not found"
                self.passFlag = 0
                MyLog.error("Failed!!! characters not found")
                print "Failed!!! characters not founded"
            #self.inputC.deleteEntry()

        self.inputC.deinitParams()
Exemple #7
0
    def runRouteCalculation(self):
        ##################################

        def checkParkPop():
            popString = "驻车信息"
            for i in range(5):
                self.grabAndHandleImage(
                    r"D:\Temp\TA\Mask\NaviParkingInformation.xml",
                    popString.decode("utf-8"))
                chResult, disL, flag, rect = self.handleImage.recognizeCharacters(
                )

                if disL > 0.9:
                    time.sleep(5)
                else:
                    return 1
            return 0

        def setPOI(coordX, coordY):
            self.touch.touchScreen(coordX, coordY, 500, 1, 1)
            time.sleep(3)
            self.touch.touchScreen(260, 145, 500, 1, 1)
            time.sleep(10)

        if self.recogCharacter["RouteCalculation"]:
            for case in self.recogCharacter["RouteCalculation"]:
                MyLog.debug("Now run RouteCalculation case")
                print self.report

                self.routeCalPrecondition()

                if not self.recogCharacter["RouteCalculation"][case]["Map"]:

                    MyLog.debug("Now run " + case + ":" +\
                                self.recogCharacter["RouteCalculation"][case]["Name"])

                    coords = self.recogCharacter["RouteCalculation"][case][
                        "Coords"]

                    #Set POI
                    setPOI(coords[0], coords[1])
                    #Check parking
                    if not checkParkPop():  #timeout.

                        MyLog.error("Time out, Test Failed")

                        print "Time out, Test Failed!"

                    else:

                        self.grabAndHandleImage(
                            r"D:\Temp\TA\Mask\NaviRouteCalculationIconCheck.xml",
                            None)
                        likelihood = self.handleImage.recognizeImage(
                            r"D:\Temp\TA\MGB\RecogImage\Flag.png")

                        if likelihood > 0.60:
                            MyLog.debug(
                                "Get the flag Passed, and then check route information"
                            )
                            print "Get the flag Passed, and then check route information"

                            #After find the route flag then you should check the route info flag and get route mile info
                            #Then check the route info flag first
                            self.grabAndHandleImage(
                                r"D:\Temp\TA\Mask\RouteFlagInformation.xml",
                                None)
                            likelihood = self.handleImage.recognizeImage(
                                r"D:\Temp\TA\MGB\RecogImage\RouteCalFlag.PNG",
                                None)
                            if likelihood > 0.75:
                                MyLog.debug("Get the route info flag")

                                print "Get the route info flag"
                            else:

                                MyLog.error("Get the route info failed")
                                print "Get the route info failed"

                            #Get the route mile info
                            self.grabAndHandleImage(
                                r"D:\Temp\TA\Mask\RouteMilInformation.xml",
                                None)
                            result, disL, flag, rect, countNum = self.handleImage.recognizeCharacters_AIn(
                            )

                            print "#########################################"
                            print result
                            for i in range(countNum):
                                try:
                                    print result[i]
                                except Exception as e:
                                    MyLog.error("Return result is wrong " +
                                                e.message)
                                    print "return result is wrong " + e.message

                            self.touch.touchScreen(440, 135, 500, 1, 1)
                            time.sleep(3)

                        else:
                            MyLog.error("Failed, couldn't find the flag")
                            print "Failed, couldn't find the flag"

                            self.touch.touchScreen(440, 135, 500, 1, 1)
                            time.sleep(3)

                elif self.recogCharacter["RouteCalculation"][case]["Map"].get(
                        "drag"):

                    MyLog.debug("Now run " + case + ":" +\
                                self.recogCharacter["RouteCalculation"][case]["Name"])
                    coordsDrag = self.recogCharacter["RouteCalculation"][case][
                        "Map"]["drag"]
                    self.touch.dragCoords(coordsDrag[0], coordsDrag[1],
                                          coordsDrag[2], coordsDrag[3])

                    coords = self.recogCharacter["RouteCalculation"][case][
                        "Coords"]

                    #Set POI
                    setPOI(coords[0], coords[1])
                    #Check parking
                    if not checkParkPop():
                        MyLog.error("Time out, Test Failed")
                        print "Time out, Test Failed"

                    else:
                        #Need to drag the screen
                        self.touch.dragCoords(coordsDrag[0], coordsDrag[1],
                                              coordsDrag[2], coordsDrag[3])

                        time.sleep(3)
                        self.grabAndHandleImage(
                            r"D:\Temp\TA\Mask\NaviRouteCalculationIconCheck.xml",
                            None)
                        likelihood = self.handleImage.recognizeImage(
                            r"D:\Temp\TA\MGB\RecogImage\Flag.png")

                        if likelihood > 0.60:
                            MyLog.debug("Recognize image passed")
                            print "Passed"
                            self.touch.touchScreen(200, 650, 500, 1,
                                                   1)  #Touch navi deviation
                            time.sleep(3)

                            #After find the route flag then you should check the route info flag and get route mile info
                            #Check the route info flag first
                            self.grabAndHandleImage(
                                r"D:\Temp\TA\Mask\RouteFlagInformation.xml",
                                None)
                            likelihood = self.handleImage.recognizeImage(
                                r"D:\Temp\TA\MGB\RecogImage\RouteCalFlag.PNG",
                                None)
                            if likelihood > 0.75:

                                MyLog.debug("Get the route info flag")
                                print "Get the route info flag"
                            else:

                                MyLog.error("Get the route info failed")
                                print "Get the route info failed"

                            #Get the route mile info
                            self.grabAndHandleImage(
                                r"D:\Temp\TA\Mask\RouteMilInformation.xml",
                                None)
                            result, disL, flag, rect, countNum = self.handleImage.recognizeCharacters_AIn(
                            )

                            print "#########################################"
                            print result
                            for i in range(countNum):
                                try:
                                    print result[i]
                                except Exception as e:

                                    MyLog.error("return result is wrong " +
                                                e.message)
                                    print "return result is wrong " + e.message

                            self.touch.touchScreen(
                                440, 135, 500, 1,
                                1)  #Touch calc navi route calculation
                            time.sleep(3)

                        else:

                            MyLog.error("Failed, couldn't find the flag")
                            print "Failed, couldn't find the flag"

                            self.touch.touchScreen(200, 650, 500, 1,
                                                   1)  #Touch navi deviation
                            time.sleep(3)
                            self.touch.touchScreen(
                                440, 135, 500, 1,
                                1)  #Touch cancel navi route calculation
                            time.sleep(3)