// Start by launching the main app
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("Android");
options.setPlatformVersion("12");
options.setAppPackage("com.example.demoapp");
options.setDeviceName("Pixel_4_Emulator");
options.setAutomationName("UiAutomator2");
options.setApp("/path/to/your/app.apk");
URL appiumServerUrl = new URL("http://localhost:4723");
AndroidDriver driver = new AndroidDriver(appiumServerUrl, options);
// Step 1: Open the Notification Drawer
driver.openNotifications();
Thread.sleep(2000); // Wait a moment for notifications to appear
// Step 2: Locate the Notification by text or ID (if possible)
WebElement notificationTitle = driver.findElement(By.xpath("//android.widget.TextView[@text='Your Notification Title']"));
WebElement notificationText = driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Your notification message')]"));
// Step 3: Validate Notification Content
if (notificationTitle != null && notificationText != null)
{
System.out.println("Notification found with correct title and message!");
// (Optional) Step 4: Click on the Notification
notificationTitle.click();
}
else
{
System.out.println("Notification not found or text did not match!");
}
driver.quit();
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Android";
options.DeviceName = "Pixel_4_Emulator";
options.AutomationName = "UiAutomator2";
options.App = "/path/to/your/app.apk";
var serverUri = new Uri("http://localhost:4723");
AndroidDriver driver = new AndroidDriver(serverUri, options);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(90);
// Step 1: Open the Notification Drawer
driver.OpenNotifications();
Thread.Sleep(2000); // Wait a moment for notifications to appear
// Step 2: Locate the Notification by text or ID (if possible)
IWebElement notificationTitle = driver.FindElement(By.XPath("//android.widget.TextView[@text='Your Notification Title']"));
IWebElement notificationText = driver.FindElement(By.XPath("//android.widget.TextView[contains(@text, 'Your notification message')]"));
// Step 3: Validate Notification Content
if (notificationTitle != null && notificationText != null)
{
Console.WriteLine("Notification found with correct title and message!");
// (Optional) Step 4: Click on the Notification
notificationTitle.Click();
}
else
{
Console.WriteLine("Notification not found or text did not match!");
}
driver.Quit();
options = UiAutomator2Options()
options.platform_name = "Android"
options.platformVersion = '15'
options.device_name = "YourDeviceName"
options.app_activity = ".MainActivity"
options.App = "/path/to/your/app.apk"
driver = webdriver.Remote('http://localhost:4723', options=options)
driver.implicitly_wait(30)
# Step 1: Open the Notification Drawer
driver.open_notifications()
time.sleep(5) # Wait a moment for notifications to appear
# Step 2: Locate the Notification by text or ID( if possible)
notification_title = driver.find_element(By.XPATH, "//android.widget.TextView[@text='Your Notification Title']")
notification_text = driver.find_element(By.XPATH, "//android.widget.TextView[contains(@text, 'Your notification message')]")
# Step 3: Validate Notification Content
if notification_text and notification_title:
print("Notification found with correct title and message!")
# (Optional) Step 4: Click on the Notification
notification_title.click()
else:
print("Notification not found or text did not match!")
driver.quit()
// Define Desired Capabilities
const capabilities =
{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'Pixel 7 API 34',
'appium:platformVersion':'14',
'appium:app': '/path/to/my.app',
'appium:appActivity': '.MainActivity',
};
// Define Server Configuration
const wdOpts = {
hostname: 'localhost',
port: 4723,
logLevel: 'info',
capabilities,
};
const driver = await remote({capabilities: wdOpts});
// Open the Notification Drawer
await driver.openNotifications();
// Locate the Notification by text or ID (if possible)
let notificationTitle = driver.$("//android.widget.TextView[@text='Your Notification Title']");
let notificationText = driver.$("//android.widget.TextView[contains(@text, 'Your notification message')]");
// Validate Notification Content
if (notificationTitle != null && notificationText != null)
{
// (Optional) Step 4: Click on the Notification
console.log("Notification found with correct title and message!");
await notificationTitle.click();
}
else
{
console.log("Notification not found or text did not match!");
}
val options = UiAutomator2Options()
options.setPlatformName("Android")
options.setDeviceName("Pixel_4_Emulator") // Replace with the name of your device/emulator
options.setAutomationName("UiAutomator2")
options.setApp("/path/to/your/app.apk") // Path to your APK file
// Initialize the AndroidDriver
val serverUrl = URI.create("http://localhost:4723").toURL()
val driver = AndroidDriver(serverUrl, options)
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30))
// Step 1: Open the Notification Drawer
driver.openNotifications()
Thread.sleep(2000) // Wait a moment for notifications to appear
// Step 2: Locate the Notification by text or ID (if possible)
val notificationTitle = driver.findElement(By.xpath("//android.widget.TextView[@text='Your Notification Title']"))
val notificationText = driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Your notification message')]"))
// Step 3: Validate Notification Content
assertTrue(notificationText.isDisplayed )
println("Notification found with correct title and message!")
// (Optional) Step 4: Click on the Notification
notificationTitle.click()
driver.quit()