Search code examples
seleniumtestngappium

unexpected behaviour in Appium


I am new in appium. I am running following test for IOS

@Test
public void Login() throws InterruptedException{
Thread.sleep(3000);
driver.findElement(By.xpath("//window[1]/textfield[9]")).sendKeys("john");
driver.findElement(By.xpath("//window[1]/secure[1]")).sendKeys("asdf1234");
driver.findElement(By.name("btn checkbox")).click();

driver.findElement(By.name("Login")).click();

Thread.sleep(6000);

here it works fine, it logins, but when I comment driver.findElement(By.name("btn checkbox")).click(); this line it does not login, but shows test is passed, there is no single exception
please can anybody tell me what is problem here?


Solution

  • It seems that your test doesn't check if it's logged in or not. You're performing the actions to make it login, but you're not actually validating anything. You're smoke testing.

    What you want to do here...

    • Build something that lets you check for any indicator that you have finished the login process. (like welcome label!)

    • Use an explicit wait to do this.

    • Define your success criteria. Login usually takes 10 seconds. Our success criteria may be anything under 25 seconds.

    • If it doesn't find the element after 25 seconds in the exception that's thrown (TimeoutException), you should return something like "None", else return the element.

    Should look something like this:

    WebElement welcomeLabel = (new WebDriverWait(driver, 25)) .until(ExpectedConditions.presenceOfElementLocated(By.name("welcomeLabel")));

    And then you'll say something like this: Assert.assertIsNotNone(welcomeLabel) this assertion is what makes this NOT a smoke test