Exemplo n.º 1
0
 def swipe(self, points):
     automationName = self.driver.capabilities.get('automationName')
     last_x = 0
     last_y = 0
     if (automationName == 'Appium'):
         action_appium = TouchAction(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_appium = action_appium.press(None, x, y).wait(200)
             elif (i == (len(points) - 1)):
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200).release()
                 action_appium.perform()
             else:
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200)
             last_x = x
             last_y = y
     else:
         action_selendroid = TouchActions(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_selendroid.tap_and_hold(x, y)
             elif (i == (len(points) - 1)):
                 action_selendroid.move(x, y).release(x, y).perform()
             else:
                 action_selendroid.move(x, y)
Exemplo n.º 2
0
 def act(self, x):
     x = int(x)
     if x == self.width:
         x -= 1
     actions = TouchActions(self.browser)
     actions.tap_and_hold(x, 200)
     actions.move(x, 200).perform()
     time.sleep(1)
     actions.release(x, 200).perform()
Exemplo n.º 3
0
    def verify_action(self):
        try:
            iLoginCounDown = self.driver.find_element_by_xpath(
                '//*[@id="iLoginCounDown"]')
            time.sleep(1)
            r = requests.post('http://z-sms.com/admin/smslist.php', data = {'PhoNum':self.phone})
            sms = r.json()

            print(sms)
        except NoSuchElementException:
            print("No element found")

            sendCodeBtn = self.driver.find_element_by_xpath(
                '//*[@id="sendCodeBtn"]')
            sendCodeBtn.click()
            time.sleep(3)
            try:
                yodaBox = self.driver.find_element_by_xpath('//*[@id="yodaBox"]')
            except NoSuchElementException:
                self.verify_action()
            touch = TouchActions(self.driver)
            r = random.randint(1,2)
            if r == 1:
                tracks = self.get_track(270)
            else:
                offsets, tracks = easing.get_tracks(265, 10, 'easeInOutQuint')
                
            print(tracks)
            # offsets, tracks = easing.get_tracks(265, 10, 'easeInOutQuint')
            # print(tracks)
            # print(offsets)
            loc = yodaBox.location
            x = loc['x']+10
            y1 = loc['y']+10
            y2 = y1 +3
            y3 = y1 +6
            touch.tap_and_hold(x, y1)
            y_d = []
            # for track in track_list:
            #     x += track
            #     tmp = y + random.randint(-2,3) 
            #     touch.move(x+track, tmp)
            for i,track in enumerate(tracks):
                x += track
                if i/len(tracks) < 1/5 or i/len(tracks) > 4/5:
                    y = y1
                elif 2/5 <= i/len(tracks) <= 3/5:
                    y = y3
                else:
                    y = y2 
                y_d.append(y)
                touch.move(x, y)
            touch.release(x, y).perform()
            print(y_d)
            self.verify_action()
Exemplo n.º 4
0
def _scroll(context, direction, percentage=50):
    """
    :type context: HackedContext
    """
    if isinstance(context.driver, iOSWebDriver):
        context.driver.swipe(direction, percentage)
    else:
        touch_action = TouchActions(context.driver).tap_and_hold(directions[direction][0][0], directions[direction][0][1])
        touch_action.move(directions[direction][1][0], directions[direction][1][1])
        touch_action.release(directions[direction][1][0], directions[direction][1][1])
        touch_action.perform()
Exemplo n.º 5
0
 def swipe(self, points, dir):
     if dir is not None:
         if dir == 'up':
             self.driver.swipe(self.window_size["width"] * 0.5,
                               self.window_size["height"] * 0.2,
                               self.window_size["width"] * 0.5,
                               self.window_size["height"] * 0.8, 1000)
         elif dir == 'down':
             self.driver.swipe(self.window_size["width"] * 0.5,
                               self.window_size["height"] * 0.8,
                               self.window_size["width"] * 0.5,
                               self.window_size["height"] * 0.2, 1000)
         elif dir == 'left':
             self.driver.swipe(self.window_size["width"] * 0.9,
                               self.window_size["height"] * 0.5,
                               self.window_size["width"] * 0.1,
                               self.window_size["height"] * 0.5, 1000)
         elif dir == 'right':
             self.driver.swipe(self.window_size["width"] * 0.1,
                               self.window_size["height"] * 0.5,
                               self.window_size["width"] * 0.9,
                               self.window_size["height"] * 0.5, 1000)
         return
     last_x = 0
     last_y = 0
     if self.automationName == 'Appium':
         action_appium = TouchAction(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if i == 0:
                 action_appium = action_appium.press(None, x, y).wait(20)
             elif i == (len(points) - 1):
                 action_appium = action_appium.move_to(
                     None, x - last_x, y - last_y).wait(20).release()
                 action_appium.perform()
             else:
                 action_appium = action_appium.move_to(
                     None, x - last_x, y - last_y).wait(20)
             last_x = x
             last_y = y
     else:
         action_selendroid = TouchActions(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if i == 0:
                 action_selendroid.tap_and_hold(x, y)
             elif i == (len(points) - 1):
                 action_selendroid.move(x, y).release(x, y).perform()
             else:
                 action_selendroid.move(x, y)
Exemplo n.º 6
0
    def step(self, x):
        actions = TouchActions(self.browser)
        actions.tap_and_hold(x, 200)
        actions.move(x, 200).perform()
        time.sleep(1)
        actions.release(x, 200).perform()
        time.sleep(3)

        score = self.browser.execute_script("return cc.js.getClassByName('GameManager').Instance.score;")
        done = False
        if score < self.last_score:
            print(score, self.last_score)
            done = True
        reward = score - self.last_score
        self.last_score = score
        return self.get_state(), reward, done
Exemplo n.º 7
0
 def act(self, x):
     actions = TouchActions(self.browser)
     actions.tap_and_hold(x, 200)
     actions.move(x, 200).perform()
     time.sleep(1)
     actions.release(x, 200).perform()