Как удалить все уведомления из панели уведомлений в Android с помощью appium на любом из устройств Android.
Я старался
MobileElement clearallnotification=null;
driver.openNotifications();
try {
clearallnotification= driver.findElement(By.xpath("//android.widget.ImageView[contains(@content-desc, 'Clear all notifications')]"));
clearallnotification.click();
}catch(ElementNotFoundException e) {
clearallnotification= driver.findElementById("com.android.systemui:id/delete");
clearallnotification.click();
}
driver.pressKeyCode(AndroidKeyCode.BACK);
Но это работает только для определенных устройств, как сделать его универсальным для всех типов устройств?




Приведенный ниже код сделает это. Это сработало для меня.
из веб-драйвера импорта appium из appium.webdriver.common.touch_action импортировать TouchAction из времени импортировать сон импортировать pytest
класс TestScrollAndroid: «Класс для запуска тестов с приложением Chess Free»
@pytest.fixture(scope='function')
def driver(self, request):
"Setup for the test"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1.0'
desired_caps['deviceName'] = 'Realme 2 Pro'
desired_caps['noReset'] = True
desired_caps['udid'] = '2032609e'
desired_caps['allowTestPackages'] = True
# Returns abs path relative to this file and not cwd
desired_caps['app'] = "D:\\Chess Free.apk"
desired_caps['appPackage'] = 'uk.co.aifactory.chessfree'
desired_caps['appActivity'] = '.ChessFreeActivity'
#desired_caps['autoWebview'] = True
#calling_request = request._pyfuncitem.name
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
def tearDown():
print("Tear down the test")
driver.quit()
request.addfinalizer(tearDown)
return driver
def test_scroll_notificaion(self,driver):
driver.open_notifications()
def test_clear_all_notification(self, driver):
driver.open_notifications()
if (driver.find_elements_by_id("com.android.systemui:id/clear_all_button"))
element = driver.find_element_by_id("com.android.systemui:id/clear_all_button")
element.click()
assert(not driver.find_elements_by_id("android:id/title"))
Это то, что пробовали driver.openNotifications(); try { clearallnotification= driver.findElement(By.xpath("//android.widget.ImageView[contains(@content-desc, 'Удалить все уведомления')]")); очистить все уведомления.щелчок(); } catch(ElementNotFoundException e) { clearallnotification= driver.findElementById("com.android.systemui:id/delete"); очистить все уведомления.щелчок(); } driver.pressKeyCode(AndroidKeyCode.BACK);
Какую ошибку вы получаете?
Если вы используете Webdriver.IO, вот решение: $('~Очистить,Кнопка').click()