java - 使用 appium 从任何 android 设备的通知栏中清除所有通知
问题描述
如何在任何 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 导入 webdriver 从 appium.webdriver.common.touch_action 导入 TouchAction 从时间导入睡眠导入 pytest
class 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"))
推荐阅读
- docker - 将 Redash 集成到 Docker 容器中
- mysql - 如何从MYSQL中的外部IF语句退出
- webpack - React-Leaflet 与 Gatsby
- c# - 获取 NotSupportedException:不支持指定的方法。NHibernate C#
- asp.net - 如何防止 Asp.net 中的会话劫持
- php - 更新我的记录时出错
- ruby-on-rails - 在 Heroku 环境中从 Rails 应用程序发送电子邮件
- php - 如何使用 codeigniter 在 PHP 中验证日期表单
- python - 生成缺失时间间隔列表
- ios - 从 CallKit UI 切换到应用内 UI