public void Chrome_MobileDriver(EnumPhoneType phone, bool touch) { ratDriver = new RatDriver <ChromeDriver>(phone, touch); ratDriver.NavigateToPage(WebsiteToTest); Assert.IsTrue(ratDriver.GetBrowserWindowUrl().Contains(WebsiteUrl)); ratDriver.ClosePagesAndQuitDriver(); }
/// <summary> /// Starts a Chrome Mobile Emuation driver /// </summary> /// <param name="phoneType">The type of device to emulate</param> /// <param name="touch">Whether to respond to toucn events</param> /// <returns>An instance of the Chrome Driver set to emulate a particular device</returns> public IWebDriver StartMobileDriver(EnumPhoneType phoneType, bool touch) { try { SetOptions(); PhoneTypes.TryGetValue(phoneType, out string phoneName); Options.EnableMobileEmulation(phoneName); SetMobileDriverService(); AddAdditionalCapabilities(); Driver = new ChromeDriver(Service, Options, BaseSettings.Timeout); return(Driver); } catch (Exception ex) { switch (BaseSettings.DebugLevel) { case EnumConsoleDebugLevel.Human: Console.Out.WriteLine("Could not start the chrome driver's mobile emulation functionality."); Console.Out.WriteLine("Please investigate the changes you have made to your config file."); break; case EnumConsoleDebugLevel.NotSpecified: case EnumConsoleDebugLevel.Message: Console.Out.WriteLine(ex.Message); break; case EnumConsoleDebugLevel.StackTrace: Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(ex.StackTrace); break; } return(null); } }
/// <summary> /// Creates a chrome driver instance in modile emulation mode /// </summary> /// <param name="type">Which type of phone to emulate</param> /// <param name="touch">(Optional Parameter) Whether touch actions are enabled</param> /// <param name="driverSettings">Settings file for the Driver being instantiated.</param> /// <param name="performanceTimings">Whether to obtain performance timings for the browser.</param> public RatDriver(EnumPhoneType type, [Optional, DefaultParameterValue(false)] bool touch, [Optional, DefaultParameterValue(null)] ChromeSettings driverSettings, [Optional, DefaultParameterValue(false)] bool performanceTimings) { try { RecordPerformance = performanceTimings; if (performanceTimings) { InitialiseRatWatch(performanceTimings); } string driverType = typeof(TWebDriver).Name; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationStart); } if (typeof(TWebDriver) == typeof(ChromeDriver)) { EstablishDriverSettings(driverType); if (!_runTests) { throw new LiberatorOSException(_browserError); } ChromeDriverControl controller = new ChromeDriverControl(driverSettings); Driver = (TWebDriver)controller.StartMobileDriver(type, touch); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationEnd); } } else { Console.Out.WriteLine("{0} does not currently allow the loading of profiles.", driverType); Console.Out.WriteLine("Please switch to Chrome if mobile emulation is required"); } if (performanceTimings) { RatTimerCollection.StopTimer(EnumTiming.Instantiation); } } catch (Exception ex) { if (ex.GetType() != typeof(LiberatorOSException)) { Console.Out.WriteLine("An unexpected error has been detected."); } HandleErrors(ex); } }
public void Chrome_MobileDriver_ClickLink(EnumPhoneType phone, bool touch) { ratDriver = new RatDriver <ChromeDriver>(phone, touch); ratDriver.NavigateToPage(WebsiteToTest); Assert.IsTrue(ratDriver.GetBrowserWindowUrl().Contains(WebsiteUrl)); var devLink = ratDriver.FindElementByXPath(".//*[@id='just-intro']/div/div/div[1]/a"); Assert.IsTrue(ratDriver.ElementExists(devLink)); ratDriver.ClickLinkAndWait(devLink); Assert.IsTrue(ratDriver.GetBrowserWindowUrl().Contains("developments")); ratDriver.ClosePagesAndQuitDriver(); }
public void Chrome_MobileDriver_ClickMenu(EnumPhoneType phone, bool touch) { ratDriver = new RatDriver <ChromeDriver>(phone, touch); ratDriver.NavigateToPage(WebsiteToTest); Assert.IsTrue(ratDriver.GetBrowserWindowUrl().Contains(WebsiteUrl)); var buttonLink = ratDriver.FindElementByXPath("html/body/div[1]/div/div[1]/button"); Assert.IsTrue(ratDriver.ElementExists(buttonLink)); ratDriver.ClickLink(buttonLink); var devLink = ratDriver.FindElementByXPath("html/body/div[1]/div/div[2]/ul/li[2]/a"); ratDriver.ClickLinkAndWait(devLink); Assert.IsTrue(ratDriver.GetBrowserWindowUrl().Contains("developments")); ratDriver.ClosePagesAndQuitDriver(); }
/// <summary> /// 电话验证 /// </summary> /// <param name="PhoneType">电话类型(默认是手机)</param> /// <param name="Multiple">是否多个(默认单个)</param> public PhoneAttribute(EnumPhoneType PhoneType = EnumPhoneType.Cellphone, bool Multiple = false) { _PhoneType = PhoneType; _Multiple = Multiple; }
/// <summary> /// Sets the mobile emulation settings for Chrome /// </summary> /// <param name="phoneType">The type of device to emulate</param> /// <param name="touchEvents">Whether to respond to touch events</param> /// <returns>The Chrome Mobile Emulation Device Settings</returns> private ChromeMobileEmulationDeviceSettings SetChromeMobileEmulationDeviceSettings(EnumPhoneType phoneType, bool touchEvents) { try { ChromeMobileEmulationDeviceSettings settings = new ChromeMobileEmulationDeviceSettings() { EnableTouchEvents = touchEvents, UserAgent = phoneType.ToString(), }; return(settings); } catch (Exception ex) { switch (BaseSettings.DebugLevel) { case EnumConsoleDebugLevel.Human: Console.Out.WriteLine("Unable to set Chrome Mobile Emulation settings."); Console.Out.WriteLine("Device Type: " + phoneType.ToString() + "| Touch Events: " + touchEvents.ToString()); break; case EnumConsoleDebugLevel.NotSpecified: case EnumConsoleDebugLevel.Message: Console.Out.WriteLine(ex.Message); break; case EnumConsoleDebugLevel.StackTrace: Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(ex.StackTrace); break; } return(null); } }
/// <summary> /// Sets the mobile emulation settings for the Chrome Driver /// </summary> /// <param name="phoneType">The type of device to emulate</param> /// <param name="touchEvents">Whether to respond to toucn events</param> public void SetMobileEmulationOptions(EnumPhoneType phoneType, bool touchEvents) { SetOptions(); Options.EnableMobileEmulation(SetChromeMobileEmulationDeviceSettings(phoneType, touchEvents)); AddAdditionalCapabilities(); }