Appium is a very well-known and useful tool when it comes to mobile app automation testing. Most of the applications in today’s world are being tested using Appium, so we have also decided to use Appium to automate our mobile applications for iOS devices.
Normally, for scripting purposes, the Java language is preferred because it has very good documentation and support over the internet. However, in our case, our client was using both the .NET framework and C# themselves, so they suggested that we use C# for scripting.
The challenge that we faced using C# as a scripting language is that there is not much outside support to resolve issues, so I prepared this blog to provide a basic understanding to a novice user of using C# for mobile app automation testing. This blog will help you set up an Appium server and an Appium client, as well as help you prepare and execute test scripts and analyze the test results.
Here is the architecture through which Appium communicates with both the mobile device and the client.
There are two ways to do the entire setup:
We have used the second approach to perform our testing. Below are the requirements to follow this approach:
On an Appium Server machine (iOS):
On an Appium Client Machine (Windows):
Set up an Appium Server by downloading the Appium App on a Mac Machine from here.
Verify that no checkbox is checked in iOS settings and General settings on the Appium server:
Verify that both the “UDID” and “Bundle ID” checkboxes are checked in iOS settings (correct details are provided in corresponding text boxes) and no checkbox is checked in General settings on the Appium server:
Prepare the test scripts in Visual Studio
Sample Test Script for Simulator
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Remote; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SeleniumHelloWorld { class Simulator { public IWebDriver driver; [TestFixtureSetUp] public void Class1() { //Setting Capabilities DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("platformName", "iOS"); capabilities.SetCapability("platformVersion", "8.1"); capabilities.SetCapability("platform", "Mac"); capabilities.SetCapability("deviceName", "iPhone 6"); capabilities.SetCapability("app", "/Users/ADMIN/Desktop/CAMobileApp.app"); //Connecting to Appium Server driver = new RemoteWebDriver(new Uri("http://172.xx.xx.169:4723/wd/hub"), capabilities); } [Test()] public void VerifyMenuSimulator() { //Test to login into app driver.FindElement(By.XPath("//UIATextField[1]")).SendKeys("username"); driver.FindElement(By.XPath("///UIASecureTextField[1]")).SendKeys("password"); driver.FindElement(By.XPath("///UIAButton[1]")).Click(); } [TestFixtureTearDown] public void End() { driver.Quit(); } } }
Sample Test Script for Real iOS Device
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Remote; using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SeleniumHelloWorld { class IOSDevice { public IWebDriver driver; [TestFixtureSetUp] public void Class1() { //Setting Capabilities DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("platformName", "iOS"); capabilities.SetCapability("platformVersion", "8.1"); capabilities.SetCapability("platform", "Mac"); capabilities.SetCapability("deviceName", "Company’s iPhone"); capabilities.SetCapability("udid", "512a44173579311b509c115b3b7651e04c75698c"); capabilities.SetCapability("bundleId", "com.ca.projectpocket"); capabilities.SetCapability("app", "/Users/ADMIN/Desktop/CAMobileApp.app"); //Connecting to Appium Server driver = new RemoteWebDriver(new Uri("http://172.xx.xx.169:4723/wd/hub"), capabilities); } [Test()] public void VerifyMenuDevice() { //Test to enter loginname & Password on login page WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(2)); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//UIAButton[1]"))); driver.FindElement(By.XPath("//UIATextField[1]")).SendKeys("username"); driver.FindElement(By.XPath("//UIASecureTextField[1]")).SendKeys("password"); driver.FindElement(By.XPath("//UIAButton[1]")).Click(); } [TestFixtureTearDown] public void End() { driver.Quit(); } } }
Running the Test
Very good sharing, and I wonder if it’s possible to run a c# testcase on windows, the purpose of this testcase is doing some verification on safari of a real MAC book, would you give me this favors?
Hi Vishal ,
How to log the success and failure results of script and generate the UIAutomation report ?
your reply will be highly Appreciated.
Thanks for sharing this Information, Got to learn new things from your Blog on Appium.
Thanks Divyadheen, i am glad you liked it.
Can you please send detailed flow Appium Automation for IOS and Android devices.
Hi Tirumala,
What exactly are you looking for in the flow?
This information help me so much, thanks for sharing!
I want to automate below IOS specific function using APPIUM. Anyone can please help me is it possible or not ? I want solution only on real devices.
IOS Specific Device Function like
Location Enable/Disable
Kill App
Put Application in background
Restart Device
Shut Down
Device Enable/disable Mobile Data
How can we install Visual Studio on MAC? If we install VMware on MAC to run the Appium client (i.e. C# scripts using Visual Studio) then how VMware’s Visual Studio interact with the ios devices?
Very good article, does the Iphone need to be connected to run the tests? I was thinking of continuous integration tests.
Well, here are sharing such a great and helpful information regarding Automation Testing. Thanks for the publish great ideas in this blog!
Well, here are sharing such a great and helpful information regarding Mobile Testing. Thanks for the publish great ideas in this blog!
Very nice…
Is it possible to automate pre-installed application like Contacts or other apps like Facebook using the above setup?
Hi Vishal,
I am using “Visual Studio for Mac” in my Mac. Without installing Eclipse, can i use VS for MAC to run UI tests on Appium? Right now i am running Xamarin tests (on Android, iOS app’s) from Visual Studio. Can i use Visual Studio MAC to run Appium tests? I already have android SDK installed in my mac. I am trying to download and install appium server (https://bitbucket.org/appium/appium.app/downloads/appium.dmg).
I am using Nunit framework, C# for scripting. Does Appium supports Nunit framework?
I need xpath for windows application control automation.Using Appium.
Can any one please help on it.
Thanks and Regards,
Suman kumar Shau
Hi Vishal,
Such a nice post.
How can i write same code which will work with both OS(Android, IOS).
Thanks,
Rajeev
Hi,
Thank you for sharing this information. Can you please advice that the .app path mentioned in capabilities is path on MAC or Windows System?
On the MAC
Hi Vishal,
Thanks for posting such a nice article. I am interested in where is IP address of IOS machine. Is this one is 172.xx.xx.169
Thanks,
Rajeev
How come you still executing UIAutomation for iOS above 9? It should now support XCUITest what iOS.
Secondly do you start your server manually or programmatically like AppiumDriverLocalService in java.
A really nice article, you totally alleviated the pain that I had in starting appium coding with C# . Thanks a lot
Hi all,
i am new to mobile automation. i have an windows machine can i start working on appium where will it work on both IOS and ANDROID devices?
Hi Vishal,
What is the role of XCode in above setup of APPIUM Server Machine (iOS)? Can you please explain that in detail.
Thanks,
Varun