3

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.

Steve Murdock
  • 709
  • 1
  • 10
  • 20
  • 3
    junit docs goes here : http://junit.sourceforge.net/javadoc/ appium's introduction here : http://appium.io/introduction.html?lang=en good practices are modulated according to the users – Naman Mar 30 '16 at 08:58
  • flagging the questions as too-broad – Naman Mar 30 '16 at 09:02
  • Thank you. I already knew the documentation of Appium. But the docs didn't help me regarding my matter. For example: Can I rename the `setUp()` method? Or is this name definition fixed specified anywhere? – Steve Murdock Mar 30 '16 at 09:47
  • Well I hope you are aware of annotations and their usage. That is what is taking care of the flow of execution in the scenario.[junit you see] and by the way, why don't you simply give it a try and see for yourself (simply the best way) ;) – Naman Mar 30 '16 at 09:50
  • Sure I will do so. But in general I'm not a big fan of trial and error. I prefer reading the docs first where I can see how to act correct and do so from the beginning. Later it's much more easier for me to explain why things happen like they do :) – Steve Murdock Mar 30 '16 at 10:02

3 Answers3

2

This link gives you a good overview of junit, especially the different annotations used by junit.

d4rty
  • 3,970
  • 5
  • 34
  • 73
2

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.

Dan
  • 2,020
  • 5
  • 32
  • 55
  • Thank you. In which order are test executed if I specify more than just 1 test? – Steve Murdock Mar 30 '16 at 09:44
  • As far as I know they are ordered from top to bottom. – Dan Mar 30 '16 at 09:54
  • @SteveMurdock : The tests are executed randomly, unless you specify `dependsOnMethod` for any. This shall help you understand : http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4 – Naman Mar 31 '16 at 03:27
1

@Test , @Before and @Before are annotations used above method defination tells the method when to execute and how to execute

@Test -> Annotations is used to identify that the method is a test case performing series of steps and matching actual result with expected result. @Before and @After -> annotations means guides the method to execute before and after each test case

Now you can see the code written in method setup() will execute before each test case and calls Appium API for test case support .(This includes platform setup to launching the app). Same way teardown method closed the app and quits test case execution.

If you want to learn more about Appium then read this Appium Tutorial

anuja jain
  • 1,367
  • 13
  • 19