Exemplo n.º 1
0
 public IWebDriver GetDriver(string driverName)
 {
     if (!Drivers.ContainsKey(driverName))
     {
         throw new Exception($"Can't find driver with name {driverName}");
     }
     try
     {
         if (RunDrivers.ContainsKey(driverName))
         {
             return(RunDrivers[driverName]);
         }
         var resultDriver = Drivers[driverName].Invoke();
         RunDrivers.Add(driverName, resultDriver);
         if (resultDriver == null)
         {
             throw new Exception($"Can't get Webdriver {driverName}. This Driver name not registered");
         }
         return(resultDriver);
     }
     catch
     {
         throw new Exception("Can't get driver.");
     }
 }
Exemplo n.º 2
0
 public IWebDriver GetDriver(string driverName)
 {
     if (!Drivers.ContainsKey(driverName))
     {
         throw new Exception($"Can't find driver with name {driverName}");
     }
     try
     {
         IWebDriver result;
         lock (_locker)
         {
             if (RunDrivers.Value == null || !RunDrivers.Value.ContainsKey(driverName))
             {
                 var rDrivers     = RunDrivers.Value ?? new Dictionary <string, IWebDriver>();
                 var resultDriver = Drivers[driverName]();
                 if (resultDriver == null)
                 {
                     throw new Exception($"Can't get Webdriver {driverName}. This Driver name is not registered");
                 }
                 rDrivers.Add(driverName, resultDriver);
                 RunDrivers.Value = rDrivers;
             }
             result = RunDrivers.Value[driverName];
         }
         return(result);
     }
     catch (Exception e)
     {
         throw new Exception($"Can't get driver: {e.Message}; StackTrace: {e.StackTrace}");
     }
 }
Exemplo n.º 3
0
 public void SwitchToDriver(string driverName)
 {
     if (Drivers.ContainsKey(driverName))
     {
         CurrentDriverName = driverName;
     }
     else
     {
         throw new Exception($"Can't switch to Webdriver {driverName}. This Driver name not registered");
     }
 }
Exemplo n.º 4
0
 public void ReopenDriver(string driverName)
 {
     if (RunDrivers.ContainsKey(driverName))
     {
         RunDrivers[driverName].Close();
         RunDrivers.Remove(driverName);
     }
     if (Drivers.ContainsKey(driverName))
     {
         GetDriver(); // TODO
     }
 }
Exemplo n.º 5
0
        public void ReopenDriver(string driverName)
        {
            var rDriver = RunDrivers.Value;

            if (rDriver.ContainsKey(driverName))
            {
                rDriver[driverName].Close();
                rDriver.Remove(driverName);
                RunDrivers.Value = rDriver;
            }
            if (Drivers.ContainsKey(driverName))
            {
                GetDriver(); // TODO
            }
        }
Exemplo n.º 6
0
        private string GetDriverName(string driverName)
        {
            if (!Drivers.ContainsKey(driverName))
            {
                return(driverName);
            }
            string newName;
            var    i = 1;

            do
            {
                newName = driverName + i++;
            } while (Drivers.ContainsKey(newName));
            return(newName);
        }
Exemplo n.º 7
0
 public string RegisterDriver(string driverName, Func <IWebDriver> driver)
 {
     if (Drivers.ContainsKey(driverName))
     {
         throw Exception($"Can't register WebDriver {driverName}. Driver with the same name already registered");
     }
     try
     {
         Drivers.Add(driverName, driver);
         CurrentDriverName = driverName;
     }
     catch (Exception e)
     {
         throw Exception($"Can't register WebDriver {driverName}. StackTrace: {e.StackTrace}");
     }
     return(driverName);
 }
        protected TDriver createDevice(string devName)
        {
            TDriver result = null;

            lock (driverSync)
            {
                if (Drivers.ContainsKey(devName))
                {
                    result = Drivers[devName];
                }
                else
                {
                    result = DriverLoader.GetImplementation <TDriver>(devName);
                    if (result == null)
                    {
                        throw new DriverException($"Unable to create a driver instance for {devName} (DeviceType={DriverType})");
                    }
                    Drivers.Add(devName, result);
                }
            }
            return(result);
        }
Exemplo n.º 9
0
 public string RegisterDriver(string driverName, Func <IWebDriver> driver)
 {
     try
     {
         string newName = driverName;
         if (Drivers.ContainsKey(driverName))
         {
             var i = 1;
             while (Drivers.ContainsKey(newName = driverName + i++))
             {
                 ;
             }
         }
         Drivers.Add(newName, driver);
         CurrentDriverName = newName;
     }
     catch
     {
         throw new Exception($"Can't register WebDriver {driverName}. Driver with the same name already registered");
     }
     return(driverName);
 }