Testing with java. Need an example test

Hello I am working on automating login Android hybrid applications with Java. Who can set an example for this test automation , as I’m confused .

What are you confused about?

A simple example using TestNG:

public void setUpDriver() {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.PLATFORM, MobilePlatform.ANDROID);
    caps.setCapability(MobileCapabilityType.APP, "/path/to/my/app");
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
    driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), caps);

public void checkActivity() {
    Assert.assertEquals(driver.currentActivity(), "com.example.MainActivity");

@AfterMethod(alwaysRun = true)
public void quitDriver() {

I need a test to check the login and password and login authorization for app

Well, I can’t really do your job for you, but I can try answering any questions you might have about how to use Appium.

OK. In the application, the default AlertDialog with two buttons to appear after 30 seconds. Please tell me , how do I make the alert waiting for ?

@Test public void ScroooToTa() throws IOException{ try { driver.findElement(By.className("android.widget.ImageButton")).click(); }catch(Exception e){ captureScreenShots(); Assert.fail(); }}

You need your test script to wait. My suggestion is one of the following:

  • If the dialog always appears after exactly 30 seconds, use Thread.sleep(…)
  • If the dialog appears after an inconsistent amount of time, use WebDriverWaits

WebDriverWaits are my favorite types of waiting used for automation. You only have to pass in an anonymous class whose only function is to check if the condition you’re waiting on has appeared.

WebDriverWait dialogWait = new WebDriverWait(driver, 60); //60 for 60 seconds
dialogWait.until(new Predicate<WebDriver>() {
    public boolean apply(WebDriver input) {
        //Your check on the app's condition goes here
        List<WebElement> myDialogButtons = input.findElements(By.className("android.widget.ImageButton"));
        return myDialogButtons != null && myDialogButtons.size() > 0;

The way this works is that the WebDriverWait class’s until() method runs your supplied apply() method in a loop until apply() returns true (or the timeout supplied in the WebDriverWait constructor is reached). Your apply() method should only return true when the state of your application is ready to continue with the rest of your test. If your apply() method returns false or throws a NoSuchElementException, then the WebDriverWait will wait 0.5 seconds before starting the next iteration in the loop.

How to verify the same thing in case of IOS apps.
I need to verify current screen Name(View controller) in IOS app