Tuesday, 22 November 2016

Getting Started with Appium

Author: Pravin Magdum

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)

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. 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
 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(""), cap, TimeSpan.FromSeconds(180));


 public void AfterAll()
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 –
 public void LoginTest()
 var username = driver.FindElement(By.Id("com.PravinMagdum.TestApp:id/ed_login_email"));
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.
Here, We have passed email id to Textbox. This will open keyboard and add text.
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.

1 comment:

  1. Inside an Availability Zone, we now have can create digital machines from predefined or customized Amazon Machine Photographs, or AMIs. An AMI might be regarded as a snapshot of machine you could load and run contained in the cloud at an Availability Zone. This is great blog. If you want to know more about this visit here AWS Cloud Certification.


Amazon EKS - Kubernetes on AWS

By Komal Devgaonkar Amazon Elastic Container Service for Kubernetes (Amazon EKS), which is highly available and scalable AWS service....