/// <summary> /// Execute a command on the target browser /// </summary> /// <param name="threadId">Id used to distinguish between multiple tests running at the same time</param> /// <param name="source">HtmlElement that initiated this command, null if none</param> /// <param name="command">Command to execute</param> /// <param name="secondsTimeout">Timeout in seconds that browser shoud wait for this command</param> /// <returns>BrowserInfo object that contains command results</returns> public BrowserInfo ExecuteCommand(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { if (source != null) { // add id to description, to make logs more informative command.Description += " id=" + source.Id; } // fire event before any command execution is started OnBrowserCommandExecuting(new BrowserCommandEventArgs(threadId, command, secondsTimeout)); BrowserInfo browserInfo = null; BrowserCommandHandler commandHandler = null; if (this._browserCommandHandlerFactory.TryGetValue(command.Handler.ClientFunctionName, out commandHandler)) { // just call a handler and if there any exceptions, let them go browserInfo = commandHandler(threadId, source, command, secondsTimeout); } else { throw new NotSupportedException(String.Format("Command '{0}' is not supported", command.Handler.ClientFunctionName)); } return(browserInfo); }
/// <summary> /// Checks if source element is a radio and handles the click if it is. /// </summary> private bool TryHandleRadioClick(HtmlElement source, out BrowserInfo browserInfo) { browserInfo = null; HtmlInputElement radio = source as HtmlInputElement; if (radio != null && radio.CachedAttributes.Type == HtmlInputElementType.Radio) { // get all radios with the given name and uncheck them ReadOnlyCollection <HtmlElement> allRadios = source.ParentPage.Elements.FindAll(new { type = "radio", name = radio.Name }); foreach (HtmlElement r in allRadios) { if (r is HtmlInputElement) { ((HtmlInputElement)r).CachedAttributes.Checked = false; } } // check current radio radio.CachedAttributes.Checked = true; browserInfo = new BrowserInfo(); return(true); } return(false); }
public static BrowserInfo Find(BrowserType type) { BrowserInfo info = new BrowserInfo(); switch (type) { case BrowserType.InternetExplorer: info.ExeName = "iexplore"; break; case BrowserType.Firefox: info.ExeName = "firefox"; break; case BrowserType.Chrome: info.ExeName = "googlechrome"; info.ExePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe"; //TDO: Need to find the path from registry key break; case BrowserType.Safari: info.ExeName = "safari"; break; } return(info); }
public void CanAccessElementsOnThePage() { ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("/test"); MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); string html = @" <html id='control1'> <foo id='control2'> <bar id='control3' /> </foo> </html> "; BrowserInfo browserInfo = new BrowserInfo(); browserInfo.Data = html; commandExecutor.SetBrowserInfo(browserInfo); HtmlPage page = new HtmlPage(); page.Elements.Refresh(); UnitTestAssert.AreEqual("html", page.RootElement.TagName); UnitTestAssert.AreEqual("foo", page.Elements.Find("control2").TagName); }
public BrowserCommand GetCommand(BrowserInfo resultOfLastCommand) { object[] results = this.Invoke("GetCommand", new object[] { resultOfLastCommand }); return((BrowserCommand)(results[0])); }
/// <summary> /// Returns the current skin for the current context. /// </summary> /// <returns></returns> public static SkinConfig GetCurrentSkin(Blog blog, HttpContextBase context) { var service = new BrowserDetectionService(); BrowserInfo capabilities = service.DetectBrowserCapabilities(context.Request); bool isMobile = capabilities.Mobile; SkinConfig skin; if (isMobile) { skin = blog.MobileSkin; if (skin.TemplateFolder != null) { return(skin); } } skin = blog.Skin; if (skin.TemplateFolder == null) { skin = DefaultSkin; } return(skin); }
private static async void Screenshot(string filename) { // Create the offscreen Chromium browser. using (var browser = new CefSharp.OffScreen.ChromiumWebBrowser()) { browser.LoadHtml("<html><head></head><body></body></html>", "http://rendering/"); browser.LoadHtml(Monster.ValloricStatBlock(), "http://rendering/"); saveFilename = filename; await Task.Delay(500); int width = 0; int height = 0; while (width == 0) { width = BrowserInfo.BrowserWidth(browser); System.Threading.Thread.Sleep(100); } while (height == 0) { height = BrowserInfo.BrowserHeight(browser); System.Threading.Thread.Sleep(100); } browser.Size = new Size(width, height); await Task.Delay(500); await browser.ScreenshotAsync().ContinueWith(DisplayBitmap); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user var user = new MembershipDto(); object userKey; MembershipCreateStatus createStatus; user.CreateUser(model.UserName, model.Email, model.Password, out userKey, out createStatus); if (createStatus.Equals(MembershipCreateStatus.Success)) { // 注册成功后,直接将表单的用户名,存入cookie FormsAuthentication.SetAuthCookie(model.UserName, false); UserDto.SetSession(userKey); // 如果开启微信授权则跳转微信OpenUrl, 跳转首页 if (BrowserInfo.IsWeChatClient() && ConfigGlobal_Arsenal.WeChatActive) { TempData["DataUrl"] = $"data-url=/Account/WeChatLogin/?scope={ScopeType.snsapi_userinfo}"; return(RedirectToAction("WeChatLogin", "Account", new { scope = ScopeType.snsapi_userinfo })); } TempData["DataUrl"] = "data-url=/"; return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("Warn", ErrorCodeToString(createStatus)); } // If we got this far, something failed, redisplay form return(View(model)); }
public FirefoxTestHandler(string inputDir, string workingDir) : base(FileName, TagFirefox, inputDir, workingDir) { var browsers = BrowserInfo.GetBrowsers("firefox"); if (browsers.Count == 1) { string appDir = browsers[0].Path; _appDir = Path.GetDirectoryName(appDir); } else { var currentBrowser = browsers[0]; for (int i = 1; i < browsers.Count; i++) { var browser = browsers[i]; if (browser.Version > currentBrowser.Version) { currentBrowser = browser; } } string appDir = currentBrowser.Path; _appDir = Path.GetDirectoryName(appDir); } }
// POST api/<controller> public HttpResponseMessage Post([FromBody] BrowserInfo data) { bool result = false; try { // Encolamos si tiene distinto de null la info data.Ip = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : ""; string QueueName = ConfigurationManager.AppSettings["BrowserInfoQueue"]; string dataString = JsonConvert.SerializeObject(data); QueueManager.InsertMessage(dataString, QueueName); result = true; } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } if (result) { return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, result)); } }
/// <summary> /// The map info to browser. /// </summary> /// <param name="x">The x.</param> /// <returns> /// The <see cref="Browser" />. /// </returns> private static Browser MapInfoToBrowser(BrowserInfo x) { return(new Browser() { BrowserName = x.browser, BrowserVersion = x.browser_version, Device = x.device, OS = x.os, OSVersion = x.os_version }); }
public JsonResult Create(WebUrl model) { //if (!Request.IsAuthenticated) // return Json(new { result = false, msg = "请您先<a href=\"/User/Login\">登录</a>" }); model = new WebUrl() { ShortUrl = YueQian.ShortUrl.Core.ShortUrlGenerator.Generator(6) }; UpdateModel(model); model.BrowerInfo = BrowserInfo.GetFullUserAgent(); model.Ip = IPAddress.IP; if (!model.Url.IsHttpUrl()) { return(Json(new { result = false, msg = "您填写网址格式错误,请重新输入!" })); } if (string.IsNullOrEmpty(model.Title)) { model.Title = "跃迁短址"; } model.CreationDate = DateTime.Now; var user = System.Web.Security.Membership.GetUser(User.Identity.Name); if (Request.IsAuthenticated) { model.UserId = user.ProviderUserKey.ToString(); model.UserName = User.Identity.Name; } else { model.UserId = "0"; model.UserName = "******"; } model.Url = model.Url.EnSureUrl(); if (Request.IsAuthenticated) { IMongoQuery condition = Query.Null; condition = Query.EQ("UserId", user.ProviderUserKey.ToString()); condition = Query.And(condition, Query.EQ("Url", model.Url)); if (MongoHelper.Instance.Has(condition, "WebUrl")) { return(Json(new { result = false, msg = "该网址您已经添加过了,请重新填写一个吧!" })); } } if (MongoHelper.Instance.Save(model)) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("<a target=\"blank\" href=\"http://yqurl.com/{0}\">yqurl.com/{0}</a>", model.ShortUrl); if (!Request.IsAuthenticated) { msg.AppendFormat(" <span class=\"reg\">快来<a href=\"/User/register?returnUrl=/User?s={0}\">注册</a>获取丰厚收益和更多功能</span> <a class=\"login\" href=\"/User/Login?returnUrl=/User?s={0}\">登录</a>", model.ShortUrl); } return(Json(new { result = true, msg = msg.ToString() })); } return(Json(new { result = false, msg = "提交短址信息错误,请重试!" })); }
/// <summary> /// Handler for GetPageDom browser command /// </summary> private BrowserInfo ExecuteCommandGetPageDom(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { BrowserInfo browserInfo = new BrowserInfo(); browserInfo.Data = this._currentBody; return(browserInfo); }
/// <summary> /// Refresh this collection of html elements from the current Dom in the web page including the specified list of attributes /// </summary> /// <param name="attributesToLoad">Collection of attribute names to load for each element</param> internal void Refresh(ICollection <string> attributesToLoad) { if (TestPage == null) { return; } //send the command to get dom of this collection BrowserCommand command = new BrowserCommand(); if (_parentElement == null) { command.Description = "GetPageDom"; command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.GetPageDom; command.Handler.RequiresElementFound = false; } else { command.Description = "GetElementDom"; command.Handler.ClientFunctionName = BrowserCommand.FunctionNames.GetElementDom; command.Handler.RequiresElementFound = true; command.Target = this.ParentElement.BuildBrowserCommandTarget(); } if (attributesToLoad != null && attributesToLoad.Count > 0) { StringBuilder attributesBuilder = new StringBuilder(); foreach (string attr in attributesToLoad) { attributesBuilder.Append(attr); attributesBuilder.Append("-"); } attributesBuilder.Length--; command.Handler.SetArguments(attributesBuilder.ToString().ToLowerInvariant()); } BrowserInfo browserInfo = this.TestPage.ExecuteCommand(_parentElement, command); HtmlElement newRoot = HtmlElement.Create(browserInfo.Data, this.TestPage, false); this.Items.Clear(); if (_parentElement == null) { this.Items.Add(newRoot); } else { foreach (HtmlElement childElement in newRoot.ChildElements) { childElement.ParentElement = _parentElement; this.Items.Add(childElement); } } OnRefresh(new EventArgs()); }
public void DataGetSet() { BrowserInfo info = new BrowserInfo(); Assert.IsNull(info.Data); info.Data = "foo"; Assert.AreEqual("foo", info.Data); }
public void ErrorMessagesGetSet() { BrowserInfo info = new BrowserInfo(); Assert.IsNull(info.ErrorMessages); info.ErrorMessages = "foo"; Assert.AreEqual("foo", info.ErrorMessages); }
public TestDataContainer(string name) { testName = name; actions = new ActionList(); VerificationErrors = new List <VerificationError>(); configSettings = Config.GetDefaultConfig(); browserInfo = new BrowserInfo(WebDriverBrowser.Browser.Chrome); SetupEvents(); }
public void CorrectBrowserInfo_Chrome_Samsung_S8() { string userAgent = "Mozilla/5.0 (Linux; Android 7.0; SM-G950F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.62 Mobile Safari/537.36"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Chrome"); Assert.IsTrue(browserInfo.MajorVersionString == "78"); Assert.IsTrue(browserInfo.Platform == "Android"); Assert.IsTrue(browserInfo.DeviceType == "Mobile"); }
public void CorrectBrowserInfo_Safari_iPad() { string userAgent = "Mozilla/5.0 (iPad; CPU OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Safari"); Assert.IsTrue(browserInfo.MajorVersionString == "12"); Assert.IsTrue(browserInfo.Platform == "iOS"); Assert.IsTrue(browserInfo.DeviceType == "Tablet"); }
public void CorrectBrowserInfo_Safari_iPhone() { string userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Safari"); Assert.IsTrue(browserInfo.MajorVersionString == "13"); Assert.IsTrue(browserInfo.Platform == "iOS"); Assert.IsTrue(browserInfo.DeviceType == "Mobile"); }
public void CorrectBrowserInfo_Chrome_Mac() { string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Chrome"); Assert.IsTrue(browserInfo.MajorVersionString == "78"); Assert.IsTrue(browserInfo.Platform == "Mac"); Assert.IsTrue(browserInfo.DeviceType == "Desktop"); }
public void CorrectBrowserInfo_Firefox_Linux() { string userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Firefox"); Assert.IsTrue(browserInfo.MajorVersionString == "70"); Assert.IsTrue(browserInfo.Platform == "Linux"); Assert.IsTrue(browserInfo.DeviceType == "Desktop"); }
public void CorrectBrowserInfo_Firefox_Windows() { string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Firefox"); Assert.IsTrue(browserInfo.MajorVersionString == "54"); Assert.IsTrue(browserInfo.Platform == "Windows"); Assert.IsTrue(browserInfo.DeviceType == "Desktop"); }
public void CorrectBrowserInfo_IE11_Windows() { string userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Internet Explorer"); Assert.IsTrue(browserInfo.MajorVersionString == "11"); Assert.IsTrue(browserInfo.Platform == "Windows"); Assert.IsTrue(browserInfo.DeviceType == "Desktop"); }
public void CorrectBrowserInfo_Edge_Windows() { string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Edge"); Assert.IsTrue(browserInfo.MajorVersionString == "18"); Assert.IsTrue(browserInfo.Platform == "Windows"); Assert.IsTrue(browserInfo.DeviceType == "Desktop"); }
public void CorrectBrowserInfo_IE11_Windows_Phone() { string userAgent = "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Internet Explorer"); Assert.IsTrue(browserInfo.MajorVersionString == "11"); Assert.IsTrue(browserInfo.Platform == "Windows Phone"); Assert.IsTrue(browserInfo.DeviceType == "Mobile"); }
public void CorrectBrowserInfo_Chrome_iOS() { string userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/78.0.3904.84 Mobile/15E148 Safari/604.1"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Chrome"); Assert.IsTrue(browserInfo.MajorVersionString == "78"); Assert.IsTrue(browserInfo.Platform == "iOS"); Assert.IsTrue(browserInfo.DeviceType == "Mobile"); }
public void CorrectBrowserInfo_Chrome_Nexus_7() { string userAgent = "Mozilla/5.0 (Linux; Android 4.4; Nexus 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.62 Safari/537.36"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Chrome"); Assert.IsTrue(browserInfo.MajorVersionString == "78"); Assert.IsTrue(browserInfo.Platform == "Android"); Assert.IsTrue(browserInfo.DeviceType == "Tablet"); }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static void ProcessQueueMessage([QueueTrigger("%BrowserInfoQueue%")] string message, TextWriter log) { KindAdsTelemetryManager manager = new KindAdsTelemetryManager(); string DatabaseName = ConfigurationManager.AppSettings["CosmosDatabaseName"]; string CollectionName = ConfigurationManager.AppSettings["CosmosBrowserCollectionName"]; BrowserInfo info = manager.GetInfo <BrowserInfo>(message); manager.SendToCosmos(info, DatabaseName, CollectionName); }
public void CorrectBrowserInfo_Samsung_Internet() { string userAgent = "Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G955F Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/9.0 Chrome/67.0.3396.87 Mobile Safari/537.36"; BrowserInfo browserInfo = getBrowserInfo(userAgent); Assert.IsTrue(browserInfo.Browser == "Samsung Internet"); Assert.IsTrue(browserInfo.MajorVersionString == "9"); Assert.IsTrue(browserInfo.Platform == "Android"); Assert.IsTrue(browserInfo.DeviceType == "Mobile"); }