public void CloseDriver_should_close_the_opened_browser_instance() { Profile browserProfile = new Profile(); browserProfile.ProfileConfig.activation.browserName = WebDriverOptions.browser_Firefox; WebDriverOptions options = new WebDriverOptions() { BrowserProfile = browserProfile, IsRemote = false, }; string specialTitle = "WebSpyBrowser.CloseDriver TEST TEST"; string[] specialWindows = new string[] { }; specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> at the beginning", specialTitle); WebSpyBrowser.Initialize(options); string changeTitleScript = string.Format("document.title = '{0}'", specialTitle); WebSpyBrowser.ExecuteJavaScript(changeTitleScript); specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(1, "Expected only 1 window with title <{0}> after new driver was created", specialTitle); WebSpyBrowser.CloseDriver(); specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> after the driver was closed", specialTitle); }
internal void RunScript() { string scriptFromEditor = view.GetJavaScriptCodeFromEditor(); Exception outException; bool isOk = false; object result = null; isOk = UIActions.PerformSlowOperation( "Operation: RunScript() / Executing JavaScript Snippet", () => { result = WebSpyBrowser.ExecuteJavaScript(scriptFromEditor); }, out outException, null, TimeSpan.FromMinutes(1) ); if (!isOk) { MyLog.Error("RunScript() Failed to execute JavaScript snippet"); MyLog.Exception(outException); if (outException != null) { throw outException; } } string consoleOut = DumpObject(result); view.AppendConsole(consoleOut); }
private void imgBox_Click(object sender, EventArgs args) { if (!ModifierKeys.HasFlag(Keys.Control)) { return; } MouseEventArgs mouse = args as MouseEventArgs; int absoluteX = mouse.X; // + ; int absoluteY = mouse.Y; // + ; absoluteX = (Convert.ToInt32(absoluteX / imgBox.ZoomFactor) + Convert.ToInt32(imgBox.HorizontalScroll.Value / imgBox.ZoomFactor)); absoluteY = Convert.ToInt32(absoluteY / imgBox.ZoomFactor) + Convert.ToInt32(imgBox.VerticalScroll.Value / imgBox.ZoomFactor); string script = @"(function showRectangle(x, y) { var rectangle = document.createElement('div'); rectangle.style.border = '3px solid red'; rectangle.style.position = 'absolute'; rectangle.style.left = x + 'px'; rectangle.style.top = y + 'px'; rectangle.style.width = '100px'; rectangle.style.height = '20px'; document.body.appendChild(rectangle); setTimeout(function cbRemoveRectangle() { doNastyStuff(); }, 2000); })(arguments[0], arguments[1]);"; WebSpyBrowser.ExecuteJavaScript(script, absoluteX, absoluteY); }