コード例 #1
0
def test_callback(app: wda.Client):
    event = threading.Event()
    def _cb(client: wda.Client, url: str):
        if url.endswith("/sendkeys"):
            pass
        assert isinstance(client, wda.Client)
        assert url.endswith("/status")
        event.set()

    app.register_callback(wda.Callback.HTTP_REQUEST_BEFORE, _cb)
    # app.register_callback(wda.Callback.HTTP_REQUEST_AFTER, lambda url, response: print(url, response))
    app.status()
    assert event.is_set(), "callback is not called"

    # test remove_callback
    event.clear()
    app.unregister_callback(wda.Callback.HTTP_REQUEST_BEFORE, _cb)
    app.status()
    assert not event.is_set(), "callback is should not be called"

    event.clear()
    app.unregister_callback(wda.Callback.HTTP_REQUEST_BEFORE)
    app.status()
    assert not event.is_set(), "callback is should not be called"

    event.clear()
    app.unregister_callback()
    app.status()
    assert not event.is_set(), "callback is should not be called"
コード例 #2
0
def test_client_status(client: wda.Client):
    """ Example response
    {
        "state": "success",
        "os": {
            "version": "10.3.3",
            "name": "iOS"
        },
        "ios": {
            "ip": "192.168.2.85",
            "simulatorVersion": "10.3.3"
        },
        "build": {
            "time": "Aug  8 2017 17:06:05"
        },
        "sessionId": "xx...x.x.x.x.x.x" # added by python code
    }
    """
    st = client.status() # json value
    assert st['state'] == 'success'
コード例 #3
0
def test_preferences(c: wda.Client):
    print("Status:", c.status())
    print("Info:", c.info)
    print("BatteryInfo", c.battery_info())
    print("AppCurrent:", c.app_current())
    # page_source = c.source()
    # assert "</XCUIElementTypeApplication>" in page_source

    app = c.session(bundle_id)
    selector = app(label="蜂窝网络")
    el = selector.get() 
    el.click()
    print("Element bounds:", el.bounds)

    logger.info("Take screenshot: %s", app.screenshot())
    
    app.swipe_right()
    app.swipe_up()

    app(label="电池").scroll()
    app(label="电池").click()
コード例 #4
0
def test_client_session_without_argument(client: wda.Client):
    s = client.session('com.apple.Health')
    session_id = client.status()['sessionId']
    assert s.id == session_id
    assert s.bundle_id == 'com.apple.Health'
    s.close()