coding=utf-8
import time
import pytest
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
class TestCs():
def setup(self):
desired_caps = {
‘platformName’: “Android”,
“platformVersion”: “9.0”,
‘deviceName’: “Q5S5T19620006140”,
‘browserName’: “Chrome”,
‘autoGrantPermissions’: True,
“automationName”: “UiAutomator2”,
“noReset”:False,
“dontStopAppOnReset”:True
}
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
time.sleep(1)
def test_webview(self):
url = "http://www.baidu.com"
self.driver.get(url=url)
WebDriverWait(self.driver, 15).until(expected_conditions.visibility_of_element_located((By.NAME, "word")))
self.driver.find_element_by_name("word").send_keys("appium")
print(self.driver.contexts)
self.driver.switch_to.context(self.driver.contexts[0])
self.driver.find_element_by_id("android:id/button2").click()
def teardown(self):
time.sleep(20)
self.driver.quit()