Run the sample web app C# test

Step 1: Setup environment

Requirements

  • .NET 9.0
  • NUnit framework
  • Appium client
  • Access key
    • You can generate an Access key using the following instruction – Access key
  • Billing unit
    • The billing unit is your team’s unique identifier, or just the word “personal” in the case of an individual account.
      More information can be found here.

Step 2: Run sample test

After setup up the environment, you can run your first web test

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Support.UI;
using System;

namespace AppiumTests
{
    public class AndroidWebTest
    {
        // Constants
        const string ProjectName = "<TEAM_CODE>";
        const string AccessKey = "mobitru_ak_......";
        const string AppiumHost = "app.mobitru.com";
        const string PlatformVersion = "15";
        const string BrowserName = "chrome";
        const string DeviceName = "Google Pixel 7";
        const string OpenUrl = "https://mobitru.com/";
        const int DefaultPageLoadTimeoutSec = 30;
        const int DefaultImplicitTimeoutSec = 3;
        const int DefaultWaitTimeoutSec = 10;

        private AndroidDriver driver;

        [SetUp]
        public void Setup()
        {
            var appiumOptions = new AppiumOptions();
            appiumOptions.AutomationName = "UIAutomator2";
            appiumOptions.PlatformName = "Android";
            appiumOptions.PlatformVersion = PlatformVersion;
            appiumOptions.DeviceName = DeviceName;
            appiumOptions.BrowserName = BrowserName;
            var appiumHubUrl = $"""https://{ProjectName}:{AccessKey}@{AppiumHost}/wd/hub""";

            driver = new AndroidDriver(new Uri($"{appiumHubUrl}"), appiumOptions);
            driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(DefaultPageLoadTimeoutSec);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(DefaultImplicitTimeoutSec);
        }

        [Test]
        public void TestAppiumDemo()
        {
            Assert.That(driver.Context, Is.EqualTo("CHROMIUM"), $"Focus is not on '{BrowserName}'");

            // Navigate to the URL
            driver.Navigate().GoToUrl(OpenUrl);

            // Wait for the Mobitru main page to load
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(DefaultWaitTimeoutSec));
            By demoButtonLocator = By.CssSelector("button[class*='demo']");
            wait.Until(d => d.FindElement(demoButtonLocator).Displayed);
            // Verify the current URL
            Assert.That(driver.Url, Is.EqualTo(OpenUrl), "Current URL is incorrect.");

            // Verify the page title
            string expectedTitle = "Mobitru: Intelligent Real Device Cloud for Mobile and Cross-Browser Testing";

            Assert.That(driver.Title, Is.EqualTo(expectedTitle), "Page title is incorrect.");
        }

        [TearDown]
        public void TearDown()
        {
            driver?.Quit();
        }
    }
}
using NUnit.Framework;
using NUnit.Framework.Legacy;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Support.UI;
using System;

namespace AppiumTests
{
    public class IOsWebTest
    {
        // Constants
        const string ProjectName = "<TEAM_CODE>";
        const string AccessKey = "mobitru_ak_......";
        const string AppiumHost = "app.mobitru.com";
        const string PlatformVersion = "18.5";
        const string BrowserName = "safari";
        const string DeviceName = "IPHONE iPhone12,1";
        const string OpenUrl = "https://mobitru.com/";
        const int DefaultPageLoadTimeoutSec = 30;
        const int DefaultImplicitTimeoutSec = 3;
        const int DefaultWaitTimeoutSec = 10;

        private IOSDriver driver;

        [SetUp]
        public void Setup()
        {
            var appiumOptions = new AppiumOptions();
            appiumOptions.AutomationName = "XCUITest";
            appiumOptions.PlatformName = "iOS";
            appiumOptions.PlatformVersion = PlatformVersion;
            appiumOptions.DeviceName = DeviceName;
            appiumOptions.BrowserName = BrowserName;
            var appiumHubUrl = $"""https://{ProjectName}:{AccessKey}@{AppiumHost}/wd/hub""";

            driver = new IOSDriver(new Uri($"{appiumHubUrl}"), appiumOptions);
            driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(DefaultPageLoadTimeoutSec);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(DefaultImplicitTimeoutSec);
        }

        [Test]
        public void TestAppiumDemo()
        {
            StringAssert.Contains("WEBVIEW", driver.Context, $"Focus is not on '{BrowserName}'");

            // Navigate to the URL
            driver.Navigate().GoToUrl(OpenUrl);

            // Wait for the Mobitru main page to load
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(DefaultWaitTimeoutSec));
            By demoButtonLocator = By.CssSelector("button[class*='demo']");
            wait.Until(d => d.FindElement(demoButtonLocator).Displayed);
            // Verify the current URL
            Assert.That(driver.Url, Is.EqualTo(OpenUrl), "Current URL is incorrect.");

            // Verify the page title
            string expectedTitle = "Mobitru: Intelligent Real Device Cloud for Mobile and Cross-Browser Testing";

            Assert.That(driver.Title, Is.EqualTo(expectedTitle), "Page title is incorrect.");
        }

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

Scroll to Top