Swipe using the Appium tool

0

I'm learning about a new mobile automated testing tool called Appium, and one of the tests I created was:

@Test
      public void Swipe () throws InterruptedException{
        Thread.sleep(4000);
        System.out.println("Vamos fazer swipe no tutorial");
        driver.swipe(75, 0, 500, 0, 10);
       }

When you run the test, it passes. However, I can not see him doing the swipe function, I do not understand how he gets through. Why does he pass?

What I wanted to get with my test: make a horizontal swipe from right to left.

    
asked by anonymous 13.02.2015 / 17:02

1 answer

1

If you did not enter any assert in your test, and no line of code raised an exception, your test will actually pass (because there was no error). You should check the status of your app after running the swipe using some Assert or even triggering an exception.

// assert com testng
Assert.assertEquals(<valor atual>, <valor esperado>);
// disparando exceção
throw new RuntimeException("Erro no app");

See an example of how to use the swipe method (extracted from link

public void swipeElementExample(WebElement el) {
  String orientation = driver.getOrientation().value();

  // pega a coordenada X do canto superior esquerdo do elemento, e adiciona a largura do elemento pra pegar o valor X da extrema direita do elemento
  int leftX = el.getLocation().getX();
  int rightX = leftX + el.getSize().getWidth();

  // pega a coordenada Y do canto superior esquedo do elemento e subtrai a altura pra pegar o menor valor Y do elemento
  int upperY = el.getLocation().getY();
  int lowerY = upperY - el.getSize().getHeight();
  int middleY = (upperY - lowerY) / 2;

  if (orientation.equals("portrait")) {
    // Swipe do centro-esquerdo para o centro-direito do elemento, em 500 ms
      driver.swipe(leftX + 5, middleY, rightX - 5, middleY, 500);
  }
  else if (orientation.equals("landscape")) {
    // Swipe do centro-direito para o centro-esquerdo do elemento, em 500ms
    driver.swipe(rightX - 5, middleY, leftX + 5, middleY, 500);
  }
}
    
07.10.2015 / 01:41