import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class GmailAppTest {
private AndroidDriver<MobileElement> driver;
@BeforeMethod
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Device");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.google.android.gm");
capabilities.setCapability("appActivity", "com.google.android.gm.ConversationListActivityGmail");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testGmailApp() {
// Login to Gmail
MobileElement emailTextBox = driver.findElement(By.id("com.google.android.gm:id/account_address"));
emailTextBox.sendKeys("your.email@gmail.com");
MobileElement nextButton = driver.findElement(By.id("com.google.android.gm:id/next_button"));
nextButton.click();
MobileElement passwordTextBox = driver.findElement(By.id("com.google.android.gm:id/password_field"));
passwordTextBox.sendKeys("yourpassword");
MobileElement signInButton = driver.findElement(By.id("com.google.android.gm:id/sign_in"));
signInButton.click();
// Compose and send an email
MobileElement composeButton = driver.findElement(By.id("com.google.android.gm:id/compose_button"));
composeButton.click();
MobileElement toTextBox = driver.findElement(By.id("com.google.android.gm:id/to"));
toTextBox.sendKeys("recipient.email@gmail.com");
MobileElement subjectTextBox = driver.findElement(By.id("com.google.android.gm:id/subject"));
subjectTextBox.sendKeys("Test Email Subject");
MobileElement bodyTextBox = driver.findElement(By.id("com.google.android.gm:id/body"));
bodyTextBox.sendKeys("Test Email Body");
MobileElement sendButton = driver.findElement(By.id("com.google.android.gm:id/send"));
sendButton.click();
// Logout from Gmail
MobileElement drawerButton = driver.