Steve Murdock Steve Murdock - 4 months ago 25
Java Question

Appium - Questions regarding test writing in Java

I'm quite new to Appium and testing. I want to write my first tests for Appium in Java using Eclipse and JUnit.

I have already written a simple test that does nothing. It compiles so far but I don't know what's going on...

I want to know how the tests work in general. I already have some experience in programming and therefore some actions going on are a bit strange to me :).

For example: As far as I can see all test layouts look like this:

public class AppiumIOSTest {

private WebDriver driver;

@Before
public void setUp() throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "ios");
capabilities.setCapability("platformVersion", "9.2");
capabilities.setCapability("deviceName","iPhone 6");
capabilities.setCapability("app", "TestApp.app");


driver = new RemoteWebDriver( new URL( "http://127.0.0.1:4723/wd/hub" ), capabilities );
}

@After
public void tearDown() throws Exception {
driver.quit();
}


@Test
public void testScriptGoesHere() throws Exception {

}
}


But where can I find documentation that tells me to write a test layout like this. I mean, why is
setUp()
called first - and from where?
Do I need a constructor and destructor?
Why is
testScriptGoesHere()
called and what about if I have more than just one test?

How do I have to access the UI elements in the app?
What's good practice and which methods I should not use?

So I would like to have any documentation that I can use. So far I haven't found anything on Google but maybe my keywords don't match...?

Greets.

Dan Dan
Answer

Hey I have done some work with Appium and like that it took a while to get used to it.

First off this Appium tutorial was a big help and also I found this tutorial on JUnit also to be very helpful

One thing to note the important thing in your code is the annotations @Before, @After etc are the most important, and not the name of the method setUp().

The setUp() method runs before every test, because of the @Before annotation and you always have to include the capabilities of the device - device name, version, platform name and the link/name of the app to be tested. These then have to be linked to the appium server.

The testScriptGoesHere() method is ran because of the @Test annotation and this is where you would include the code that automates the process of going through the app - for example logging in, navigating through activities etc. You can have multiple @Test methods and each would be run through each time the program is ran.

I personally purchased this and found it a great help.

There is no constructor or deconstructor needed as the JUnit tests are ran due to the annotations.

To test native Android apps, I have used UIAutomatorViewer to access the elements. For Hybrid apps I have used the Google Chrome console and iOS apps I used Xcode to view the elements.