Getting started with Appium

Automated software (App ) testing is an essential component of successful development projects.

This post is for Appium beginners ,who want to set up and continue automation testing for  their app. Lets get started.

Set up Appium server

# Install  Appium server and client library from here.

I am using here , Appium server for windows and C# client library.  now appium server will look like as below –

Screenshot (2)
Appium server launch

Now ,We need to supply apk file which we want to test to server. for this ,Click on android icon on top left bar. This will  look like

Screenshot (3).png If you want to set up any specific activity (screen in app) at launch while testing you can select checkbox saying Launch Activity and select from option. Now click second icon on bar (setting icon ) Screenshot (4).pngHere we will set ip address of machine. mostly localhost ip i.e. 127.0.0.1 will work ,in my case due to some network policies it didn’t worked ,So I set machine IP.This is important setting need to do. Now we are done with server setting.

Now lets open visual studio. I have used C# with Nunit testing Framework to write test cases.Add new class library Project and Install appium and nunit nuget package. This will add reference(s) of ‘appium-dotnet-driver’ ,’WebDriver.Support’,’WebDriver’ from Appium package and NunitFramework dll from installing nunit package. That’s all , lets start coding now.

Add New class say ‘TestMyApp.cs’. We will add set up and tear down methods as below

[SetUp]
 public void BeforeAll()
 {
 DesiredCapabilities cap = new DesiredCapabilities();
 cap.SetCapability(CapabilityType.Platform, "ANDROID");
 cap.SetCapability(CapabilityType.Version, "5.1.1");
 cap.SetCapability("deviceName", "Nexus 4");
 driver = new AndroidDriver<IWebElement>(new Uri("http://192.168.0.191:4723/wd/hub"), cap, TimeSpan.FromSeconds(180));

}

[TearDown]
 public void AfterAll()
 {
 driver.Quit();
 }

I have declared Global driver  object of type AppiumDriver<IWebElement>

AppiumDriver<IWebElement> driver;

Dont know [Setup] / [TearDown] ? Read here.

Now sample Testcase will be like –

 [Test]
 public void LoginTest()
 {
 var username = driver.FindElement(By.Id("com.PravinMagdum.TestApp:id/ed_login_email"));
 username.SendKeys("Pravin.magdum@gmail.com");
 driver.HideKeyBoard();
 }

lets see line by line ,

 var username = driver.FindElement(By.Id("com.eos.eos_du_su:id/ed_login_email"));

Here , We have taken user name text box on login screen in variable username. we used here Id of textbox to find element.

 username.SendKeys("pravin.magdum@gmail.com");

 here , We have passed email id to Textbox. This will open keyboard and add text.

driver.HideKeyBoard();

This line will close keyboard.Now build project and it will create Project dll. Open Test Adapter /Nunit UI console and provide dll Path.

Now Connect your android device and check appium server window ,Run server using right -Top corner button. and Run testcase from adapter. This will install Application in  connected device and run default / selected activity.That’s it.Happy Testing.

 

 

Advertisements

2 thoughts on “Getting started with Appium

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s