def test_element_all(sess: u2.Session): app = sess.xpath('//*[@text="App"]') assert app.wait() assert len(app.all()) == 1 assert app.exists elements = sess.xpath('//*[@resource-id="android:id/list"]/android.widget.TextView').all() assert len(elements) == 11 el = elements[0] assert el.text == 'Accessibility'
def test_搜索播放音乐(d: u2.Session): d.xpath('//*[@content-desc="搜索"]').click() d.xpath('//*[@resource-id="com.netease.cloudmusic:id/search_src_text"]' ).click() # 搜索框 d.send_keys("水手", clear=True) d.send_action("search") d.xpath('//*[@resource-id="com.netease.cloudmusic:id/a0w" and @text="水手"]' ).click() assert d.xpath("播放暂停").wait()
def test_watcher_from_yaml(sess: u2.Session, request): yaml_content = """--- - when: App then: click - when: Action Bar then: > def callback(d): print("D:", d) d.xpath("Alarm").click() def hello(): print("World") """ sess.xpath.apply_watch_from_yaml(yaml_content) sess.xpath.watch_background(interval=1.0) assert sess.xpath("Alarm Controller").wait(timeout=10)
def run_step(cf: bunch.Bunch, app: u2.Session, step: str): logger.info("Step: %s", step) oper, body = split_step(step) logger.debug("parse as: %s %s", oper, body) if oper == CLICK: app.xpath(body).click() elif oper == SWIPE_RIGHT: app.xpath(body).swipe("right") elif oper == SWIPE_UP: app.xpath(body).swipe("up") elif oper == SWIPE_LEFT: app.xpath(body).swipe("left") elif oper == SWIPE_DOWN: app.xpath(body).swipe("down") elif oper == SCREENSHOT: output_dir = "./output" filename = "screen-%d.jpg" % int(time.time() * 1000) if body: filename = body name_noext, ext = os.path.splitext(filename) if ext.lower() not in ['.jpg', '.jpeg', '.png']: ext = ".jpg" os.makedirs(cf.output_directory, exist_ok=True) filename = os.path.join(cf.output_directory, name_noext + ext) logger.debug("Save screenshot: %s", filename) app.screenshot().save(filename) elif oper == EXIST: assert app.xpath(body).wait(), body elif oper == WAIT: #if re.match("^[\d\.]+$") if body.isdigit(): seconds = int(body) logger.info("Sleep %d seconds", seconds) time.sleep(seconds) else: app.xpath(body).wait() else: raise RuntimeError("Unhandled operation", oper)
def test_all(sess: u2.Session): app = sess.xpath('//*[@text="App"]') assert app.wait() assert len(app.all()) == 1 assert app.exists
def test_click(sess: u2.Session): sess.xpath("App").click() assert sess.xpath("Alarm").wait() assert sess.xpath("Alarm").exists
def test_get_text(sess: u2.Session): assert sess.xpath("App").get_text() == "App"
def test_xpath_query(sess: u2.Session): assert sess.xpath("Accessibility").wait() assert sess.xpath("%ccessibility").wait() assert sess.xpath("Accessibilit%").wait()
def test_每日歌曲(d: u2.Session): d.xpath('//*[@text="每日推荐"]').click() d.xpath('播放全部').click() assert d.xpath('//*[@content-desc="分享"]').wait() assert d.xpath("播放暂停").exists assert d.xpath("下一首").exists