Esempio n. 1
0
def UiAutomator():
    current_device = airtest.cli.runner.device()
    if not current_device:
        set_serialno()
    current_device = airtest.cli.runner.device()
    dev = AutomatorDevice(current_device.serialno)
    return AutomatorWrapper(dev)
Esempio n. 2
0
 def test_serial(self):
     with patch('uiautomator.AutomatorServer') as AutomatorServer:
         AutomatorDevice("abcdefhijklmn")
         AutomatorServer.assert_called_once_with(serial="abcdefhijklmn",
                                                 local_port=None,
                                                 adb_server_host=None,
                                                 adb_server_port=None)
Esempio n. 3
0
 def setUp(self):
     self.device = AutomatorDevice()
     self.device.server = MagicMock()
     self.device.server.jsonrpc = MagicMock()
Esempio n. 4
0
    def setup_device(self) -> bool:
        """
        Sets up device through Android Debug Bridge in local port 5037.
        Returns whether or not successful. Currently only supports 16x9
        aspect ratios.
        """
        adb = Client(host='127.0.0.1', port=5037)
        devices = adb.devices()
    
        if len(devices) == 0:
            return False

        device = devices[0]

            # Configure movements based on resolution.
        res_str = device.shell('wm size').replace('Physical size: ', '')
        res_width, res_height = list(map(int, res_str.split('x')))

        # Account for status bar/nav bar.
        navbar_str = device.shell(
            "dumpsys window windows | sed -n '/Window .*NavigationBar.*" \
            ":/,/Window .*:/p' | grep 'Requested'"
            )

        statusbar_str = device.shell(
            "dumpsys window windows | sed -n '/Window .*StatusBar.*" \
            ":/,/Window .*:/p' | grep 'Requested'"
            )

        nav_match = re.search('h=(\d+)', navbar_str)
        navbar_height = int(nav_match.group(1)) if nav_match else 0

        status_match = re.search('h=(\d+)', statusbar_str)
        statusbar_height = int(status_match.group(1)) if status_match else 0

        # Adjust res width/height to fit actually usable screen.
        usable_res_height = res_height - statusbar_height - navbar_height

        # PAD uses black bars to pad screen in order to fit aspect ratio.
        # Calculate the height of the bars so that we can locate lower left corner.
        game_res_height = (res_width * self.height_ratio) // self.width_ratio
        bar_height = (usable_res_height - game_res_height)

        bottom_y = res_height - (navbar_height + bar_height)

        # Calculate radius of orbs and how much to shift when moving.
        radius = (res_width // self.board_cols) // 2
        change = (res_width) // self.board_cols

        top_y = bottom_y - self.board_rows * change 

        # Create 2d array of actual coordinates.
        coordinates = \
        [
            [
                (radius + col * change, top_y + radius + row * change)
                for col in range(self.board_cols)
            ] 
            for row in range(self.board_rows)
        ]

        # Set private variables.
        self.coordinates = coordinates
        self.device = AutomatorDevice()

        # For PAD board dimensions/coordinates
        self.bottom = bottom_y
        self.top = top_y
        self.left = 0
        self.right = res_width

        return True