Getting Started with Appium and NUnit framework
Prerequisites for running Appium Tests with NUnit
Getting Started with Appium and NUnit framework
Appium with NUnitis a powerful combination for examine mobile applications on Android and iOS. While Appium provides the mechanization library, NUnit acts as the test runner, making it easy for .NET and C # developers to structure and execute mobile test cases efficiently. This usher explain how to set up, write, and run your 1st Appium NUnit exam.
Overview
What Do You Need Before Running Appium with NUnit?
- Visual Studio for Mac (or Windows)– to write and run your C # examination scripts.
- Appium waiter– for interact with nomadic apps on Android or iOS.
- Android SDK and Virtual Devices– to create emulators for testing if physical devices aren ’ t useable.
- NUnit Framework– the test moon-curser to manage setup, execution, and teardown of your test example.
How to Set Up Appium and NUnit on Your System?
- Install Visual Studio for Mac→ Enable Android SDK and create a virtual device using Device Manager.
- Set Up Appium Server→ Enter host IP (127.0.0.1) and configure environment variable like ANDROID_HOME.
- Create an NUnit Project→ Add the required NuGet bundle (Appium libraries, NUnit adaptor).
- Prepare the Test Structure→ Define Config files and Helper Classes for reclaimable capabilities and environment particular.
How to Write Your First Appium NUnit Test?
- Setup:Defines desired capabilities and initializes the AndroidDriver.
- Test:Performs an activeness (e.g., search feature validation in a demonstration app).
- TearDown:Closes the driver to complimentary resources.
Tests can be action directly in Visual Studio by selectingRun Testfrom the NUnit window.
Why Should You Test on Real Devices?
- More Accurate Results:Emulators may not repeat real-world weather like web dip or device-specific bug.
- Wide Device Coverage:Test across both older and modish devices.
- BrowserStack Advantage:Run Appium NUnit tests on a real-device cloud, use parallel testing, and drastically reduce execution time.
This clause coverswhat Appium with NUnit is, how to set it up, how to write your first exam, and why running test on real devices give the nigh reliable results.
Prerequisites for go Appium Tests with NUnit
Before you get writing your first test in Appium with NUnit, you need below frame-up to be finish in our System (This article focuses on setting up puppet in macOS and like apparatus is also potential in Windows)
Visual Studio for Mac apparatus
Once the initiation of Optical studio for mac is completed, open the Visual studio for next setup
- Click on Tools & gt; SDK Manager
- In the Android Platform, Enable Android API and Android OS, this will download required images for running the Android Virtual Devices. Click on Apply Changes.
- Next footstep is to create a Virtual Device. To do that, click on Tools & gt; Device Manager
- Android Device Manager window will be displayed like below, you can now create a New Device, or manage Existing Devices.
- Upon clicking on the New Device button, you will see below the new Virtual gimmick creation window. Using this you can provide device name and select its Configuration. After take configuration, click on Create and this will create a new Virtual device.
- Once the gimmick is make, it will list in the Android Device Manager window. You can start the Virtual device by clicking on Play button
- Our new Android virtual device will be started and it looks like below
Appium Setup
Once the installation is completed, on opening the Appium server, the screen will look like below.
You need to enter the host IP, so let ’ s enter127.0.0.1and before starting the host you necessitate to ensure theANDROID_HOMEvariable is defined with the proper path. Enter the android sdk path and click on Save and Restart
You can now commence our Appium server with host IP set as127.0.0.1
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Project setup for extend Appium Tests with NUnit
Once you create the NUnit Test Project, you need to install below packages
Once these bundle are added, you can start publish our tests and helpers.
Writing first Appium NUnit test
Using the NUnit framework for create the test which will test the sample Android Application.
The Test class will have
- Setup& # 8211; To set the Desired capabilities and to create Android Driver
- Test& # 8211; To execute a Search feature validation in our Android Application
- TearDown& # 8211; To tear down the Android Driver
Our Project and Classes will look like below in the Solution
As you can see there are:Test Class, Config, and the Helper Class, which will receive the reclaimable static methods which will contains
- Environment Details
- Application Details (Whether we take to test IOS/Android application, Application name and path etc.)
Below is the code employ in Helper Class
using System;
namespace AppiumDotNetSamples.Helper {public static class Env {public unchanging String rootDirectory = System.IO.Path.GetFullPath ($ '' {System.AppDomain.CurrentDomain.BaseDirectory.ToString ()} / .. / .. / .. / .. ''); static public bool IsBrowserStack () {return Environment.GetEnvironmentVariable (`` BROWSERSTACK '')! = cipher;} static public Uri ServerUri () {String bsUserName = Environment.GetEnvironmentVariable (`` BROWSERSTACK_USERNAME ''); String bsAccessKey = Environment.GetEnvironmentVariable (`` BROWSERSTACK_ACCESS_KEY ''); return (bsUserName == null) || (bsAccessKey == null)? new Uri (`` http: //localhost:4723/wd/hub ''): new Uri ($ '' https: //cloudURL:80/wd/hub '');} public stable TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds (180); public unchanging TimeSpan IMPLICIT_TIMEOUT_SEC = TimeSpan.FromSeconds (10);} public static class App {static public String IOSApp () {return Env.IsBrowserStack ()? `` http: //appium.github.io/appium/assets/TestApp7.1.app.zip '': $ '' {Env.rootDirectory} /apps/TestApp.app.zip '';} static public String IOSDeviceName () {homecoming Environment.GetEnvironmentVariable (`` IOS_DEVICE_NAME '')?? `` iPhone 6s '';} inactive public String IOSPlatformVersion () {homecoming Environment.GetEnvironmentVariable (`` IOS_PLATFORM_VERSION '')?? `` 11.4 '';} static public String AndroidApp () {Console.WriteLine (Env.rootDirectory); return Env.IsBrowserStack ()? `` http: //appium.github.io/appium/assets/ApiDemos-debug.apk '': $ '' {Env.rootDirectory} /apps/ApiDemos-debug.apk '';} static public String AndroidDeviceName () {return Environment.GetEnvironmentVariable (`` ANDROID_DEVICE_VERSION '')?? `` Android '';} static public String AndroidPlatformVersion () {return Environment.GetEnvironmentVariable (`` ANDROID_PLATFORM_VERSION '')?? `` 12.0 '';}}}Let ’ s see how our Setup/BeforeAll method look like
[SetUp ()] public void BeforeAll () {DesiredCapabilities capacity = new DesiredCapabilities (); capabilities.SetCapability (MobileCapabilityType.BrowserName, `` ''); capabilities.SetCapability (MobileCapabilityType.PlatformName, App.AndroidDeviceName ()); capabilities.SetCapability (MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion ()); capabilities.SetCapability (MobileCapabilityType.AutomationName, `` UIAutomator2 ''); capabilities.SetCapability (MobileCapabilityType.DeviceName, `` Nexus ''); capabilities.SetCapability (`` appActivity '', `` .app.SearchInvoke ''); capabilities.SetCapability (MobileCapabilityType.App, App.AndroidApp ()); driver = new AndroidDriver & lt; AndroidElement & gt; (Env.ServerUri (), capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage () .Timeouts () .ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC;}As find, all the Desired Capabilities are set and so passed to AndroidDriver for creating a new driver object.
AndroidDrivercourse constructor accepts three objects
- Server URI& # 8211; Which will behttp: //localhost:4723/wd/hubwhen you run topically
- Desired Capabilities& # 8211; Which specifies Mobile Capabilities
- Timeoutfor the commands
As explained earlier, we will be finding an element in the demo app and recruit a text for hunting, and then will validate if the result contains searched textbook. For this thetryout gradewill look like below.
expend NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Enums; use OpenQA.Selenium.Appium.Android; using OpenQA.Selenium.Remote; using System; habituate AppiumDotNetSamples.Helper; namespace AppiumDotNetSamples {[TestFixture ()] public class AndroidBasicInteractionsTest {private AndroidDriver & lt; AndroidElement & gt; driver; [SetUp ()] public void BeforeAll () {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.SetCapability (MobileCapabilityType.BrowserName, `` ''); capabilities.SetCapability (MobileCapabilityType.PlatformName, App.AndroidDeviceName ()); capabilities.SetCapability (MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion ()); capabilities.SetCapability (MobileCapabilityType.AutomationName, `` UIAutomator2 ''); capabilities.SetCapability (MobileCapabilityType.DeviceName, `` Nexus ''); capabilities.SetCapability (`` appActivity '', `` .app.SearchInvoke ''); capabilities.SetCapability (MobileCapabilityType.App, App.AndroidApp ()); driver = new AndroidDriver & lt; AndroidElement & gt; (Env.ServerUri (), capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage () .Timeouts () .ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC;} [TearDown ()] public void AfterAll () {driver.Quit ();} [Test ()] public void TestShouldSendKetsToSearchBoxThenCheckTheValue () {AndroidElement searchBoxElement = driver.FindElementById (`` txt_query_prefill ''); searchBoxElement.SendKeys (`` Hello World! ``); AndroidElement onSearchRequestButton = driver.FindElementById (`` btn_start_search ''); onSearchRequestButton.Click (); AndroidElement seachText = driver.FindElementById (`` android: id/search_src_text ''); Assert.AreEqual (`` Hello World! ``, seachText.Text);}}}To run this tryout, simply double detent on the trial name in Tests window or right click on test name and select Run
If we accomplish our test, it will look like below in the Android Emulator
Accomplished example repository of the code explained can be foundhere
Test on Existent Devices
This article discussed, how to set up the tools required for lam Appium tests using NUnit. Appium, an open source test mechanization framework is very powerful and can be used to screen almost all workflows/use cases of Mobile Application across Platforms. Since are like to and interact with them, it will turn conversant for a Selenium ground tester to switch to Appium with less hear curve.
However, to get more exact test answer, it is suggested to test on real devices. BrowserStack ’ s provides all the roving devices both latest and older models in the platform.
Check out the Official Documentation to learn how to.
Using BrowserStack ’ s real devices you can also cut your testing time drastically by leveraging and scat parallel test.
# Ask-and-Contributeabout this topic with our Discord community.
Related Guides
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free