Exemplo n.º 1
0
 /// <summary>
 /// Function Name :- FnGetDriver
 /// Created By :- Pankaj Kumar
 /// Date of Creation :- 11-Apr-2020
 /// </summary>
 public void FnGetDriver()
 {
     try
     {
         if (GeneralUtil.FnVerifyText(objConfig.OS, "win"))
         {
             if (GeneralUtil.FnVerifyText(objConfig.AppType, "web"))
             {
                 if (GeneralUtil.FnVerifyText(objConfig.Browser, "chrome"))
                 {
                     ChromeOptions chromeopt = new ChromeOptions();
                     chromeopt.AddArgument("incognito");
                     chromeopt.AcceptInsecureCertificates = true;
                     driver = new ChromeDriver(chromeopt);
                 }
                 else if (GeneralUtil.FnVerifyText(objConfig.Browser, "firefox"))
                 {
                     driver = new FirefoxDriver();
                 }
                 else if (GeneralUtil.FnVerifyText(objConfig.Browser, "ie"))
                 {
                     driver = new InternetExplorerDriver();
                 }
                 if (driver != null)
                 {
                     driver.Manage().Window.Maximize();
                 }
             }
             else if (GeneralUtil.FnVerifyText(objConfig.AppType, "app"))
             {
                 if (GeneralUtil.FnVerifyText(objConfig.Browser, "androidchrome"))
                 {
                     FnStartAppiumServer();
                     AppiumOptions options = new AppiumOptions();
                     options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "android");
                     options.AddAdditionalCapability(MobileCapabilityType.BrowserName, MobileBrowserType.Chrome);
                     options.AddAdditionalCapability("chromedriverExecutable", ReadConfig.FngetChromeDriverPath().ToString());
                     options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, objConfig.DeviceOSVersion);
                     options.AddAdditionalCapability("deviceName", objConfig.DeviceName);
                     options.AddAdditionalCapability("–session-override", true);
                     driver = new AndroidDriver <AndroidElement>(new Uri(objConfig.AppiumURL), options);
                     Thread.Sleep(10000);
                 }
                 else
                 {
                     FnStartAppiumServer();
                     AppiumOptions options = new AppiumOptions();
                     options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "android");
                     options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, objConfig.DeviceOSVersion);
                     options.AddAdditionalCapability("deviceName", objConfig.DeviceName);
                     options.AddAdditionalCapability("–session-override", true);
                     options.AddAdditionalCapability("appPackage", objConfig.AppPackage);
                     options.AddAdditionalCapability("appActivity", objConfig.AppActivity);
                     driver = new AndroidDriver <AndroidElement>(new Uri(objConfig.AppiumURL), options);
                     Thread.Sleep(10000);
                 }
             }
         }
         else if (GeneralUtil.FnVerifyText(objConfig.OS, "mac"))
         {
             if (GeneralUtil.FnVerifyText(objConfig.AppType, "web"))
             {
                 if (GeneralUtil.FnVerifyText(objConfig.Browser, "chrome"))
                 {
                 }
                 else if (GeneralUtil.FnVerifyText(objConfig.Browser, "firefox"))
                 {
                 }
             }
             else if (GeneralUtil.FnVerifyText(objConfig.AppType, "app"))
             {
             }
         }
         if (driver != null)
         {
             driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
         }
     }
     catch (Exception e) { Reporter.Fail("Unable to Get the Driver " + e.StackTrace); }
 }