0

I am new to C# and Specflow. I am using appium, c# and specflow for automating my tests. I have a app.config file where i am mentioning the environment to be run into. A driver class DeviceDriver.cs where i am passing the appium server ip - DeviceDriver.cs->

{
    public enum DriverType
    {        
        IOS8P,
        IOSXR,
        IOSXS,
        IOSX,
        PIOS8P,
        ANDROIDPXL,
        ANDROIDXPRA
    }

    public class DeviceDriver
    {
        public DeviceDriver()
        {
            AppDriver driver = null;            
            string AppiumServerDriverUrl = string.Format("http://{0}:{1}/wd/hub",
                    TestEnvConfig.GetDeviceConfigItem("AppiumServerIP"),
                    TestEnvConfig.GetDeviceConfigItem("AppiumServerPort")
                );
            string driverType = TestEnvConfig.GetDeviceConfigItem("DeviceType");
            JToken profiles = JToken.Parse(Resource.ResourceManager.GetString(Settings.Default.DeviceProfile));
            JToken deviceProfile = profiles.SelectToken("devices." + driverType);

            AppDeviceCapabilities appDeviceCapabilities = new AppDeviceCapabilities()
            {
                DeviceName = deviceProfile.GetProfileCapability("deviceName"),                
                PlatformName = deviceProfile.GetProfileCapability("platformName"),
                AutomationName = deviceProfile.GetProfileCapability("automationName"),
                PlatformVersion = deviceProfile.GetProfileCapability("platformVersion")
            };
            
            if(driverType.ToLower().Contains("android"))
            {
                appDeviceCapabilities.AppPackage = deviceProfile.GetProfileCapability("appPackage");
                appDeviceCapabilities.AppActivity = deviceProfile.GetProfileCapability("appActivity");
                appDeviceCapabilities.NonStandardCapabilities.Add("unicodeKeyboard", true);
                appDeviceCapabilities.NonStandardCapabilities.Add("resetKeyboard", false);
                Console.WriteLine("Tet Execution in ANDROID device:: {0}", driverType);
            }
An AppDriver.cs where i am setting desired capability -
```namespace DISSystemIntegrationTest.Infra.Apps
{
    public enum AppType
    {
        IOS,
        ANDROID,
        JAVA,
        WINDOWS,
        EDGESESSION
    }

    public class AppDriver
    {
        public object AppiumDriver { get; set; }
        public AppDriver(AppType appType, AppDeviceCapabilities requiredDesiredCapabilities, Uri remoteUri, double defaultCommandTimeout = 300)
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("deviceName", requiredDesiredCapabilities.DeviceName);
            requiredDesiredCapabilities.NonStandardCapabilities.ToList().ForEach(pair => { desiredCapabilities.SetCapability(pair.Key, pair.Value); });
            switch (appType)
            {
                case AppType.IOS:
                    desiredCapabilities.SetCapability("udid", requiredDesiredCapabilities.UDID);
                    desiredCapabilities.SetCapability("platformVersion", requiredDesiredCapabilities.PlatformVersion);
                    desiredCapabilities.SetCapability("platformName", requiredDesiredCapabilities.PlatformName);
                    desiredCapabilities.SetCapability("automationName", requiredDesiredCapabilities.AutomationName);
                    desiredCapabilities.SetCapability("bundleId", requiredDesiredCapabilities.BundleId);
                    desiredCapabilities.SetCapability("xcodeOrgId", requiredDesiredCapabilities.XCodeOrgId);
                    IOSDriver<IWebElement> iosDriver = new IOSDriver<IWebElement>(remoteUri, desiredCapabilities, TimeSpan.FromSeconds(defaultCommandTimeout));
                    AppiumDriver = iosDriver;
                    break;
                case AppType.ANDROID:
                    desiredCapabilities.SetCapability("browserName", requiredDesiredCapabilities.BrowserName);
                    desiredCapabilities.SetCapability("platformVersion", requiredDesiredCapabilities.Version);
                    desiredCapabilities.SetCapability("platformName", requiredDesiredCapabilities.PlatformName);
                    desiredCapabilities.SetCapability("appPackage", requiredDesiredCapabilities.AppPackage);
                    desiredCapabilities.SetCapability("appActivity", requiredDesiredCapabilities.AppActivity);
                    desiredCapabilities.SetCapability("automationName", requiredDesiredCapabilities.AutomationName);
                    AppiumDriver = new AndroidDriver<IWebElement>(remoteUri, desiredCapabilities, TimeSpan.FromSeconds(defaultCommandTimeout));
                    break;
                case AppType.JAVA:
                    desiredCapabilities.SetCapability("app", requiredDesiredCapabilities.App);
                    AppiumDriver = new WindowsDriver<WindowsElement>(remoteUri, desiredCapabilities, TimeSpan.FromSeconds(defaultCommandTimeout));
                    break;                
                default:
                    throw new Exception("unknown OSType type");
            }
        }

App.config where i mention environment and device to run tests into.

```<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="DISSystemIntegrationTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    <unitTestProvider name="MsTest" />    
  </specFlow>  
  <userSettings>
    <DISSystemIntegrationTest.Properties.Settings>
      <setting name="DefaultTimeoutInSecond" serializeAs="String">
        <value>120</value>
      </setting>
      <setting name="BrowserType" serializeAs="String">
        <value>CHROME</value>
      </setting>
      <setting name="LocalContext" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="DeviceProfile" serializeAs="String">
        <value>iPhoneiMacProfile</value>
      </setting>
      <setting name="TestHarnessProxy" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="myGovIDLoginAuthenticationMocked" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="DeviceTestEnvToExecute" serializeAs="String">
        <value>UCTxDeviceServeriOS</value>
      </setting>
      <setting name="TestEnvToExecute" serializeAs="String">
        <value>UCTx20Q4Urls</value>
      </setting>
    </DISSystemIntegrationTest.Properties.Settings>

now my problem is when i am starting the appium server on 2 different ports and try to run the test parallel in test explorer then it is running only on one simulator. i am also adding one extra device in the app.config to run test
``` <setting name="DeviceTestEnvToExecute" serializeAs="String">
        <value>UCTxDeviceServeriOS</value>
In any case it is running test only on one device and not parallely. Is there any other config change which is required for me to do?
3
  • While it is possible, it is not recommended. Also, consider that to do parallel runs on mobile you'll need multiple mobile devices. Your phone can only do one thing at a time, unlike desktop where you launch multiple browser windows. – kirbycope Feb 1 at 0:05
  • I have multiple devices to run it in parallel.Can you give me pointer or sample github to check this – shashank shekhar Feb 1 at 6:20
  • The first link I shared shows how to do it in Selenium. Just substitute Appium. – kirbycope Feb 1 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.