public NewTemplateElement() { InitializeComponent(); LoadUrl loadUrl = new LoadUrl(); loadUrl.NewInstance(); availableBaseObjects.Add(loadUrl); GetInputFromUser getInputFromUser = new GetInputFromUser(); getInputFromUser.NewInstance(); availableBaseObjects.Add(getInputFromUser); SwitchWindowVisibility switchWindowVisibility = new SwitchWindowVisibility(); switchWindowVisibility.NewInstance(); availableBaseObjects.Add(switchWindowVisibility); ElementToLoad elementToLoad = new ElementToLoad(); elementToLoad.NewInstance(); availableBaseObjects.Add(elementToLoad); EventToTrigger eventToTrigger = new EventToTrigger(); eventToTrigger.NewInstance(); availableBaseObjects.Add(eventToTrigger); GetAttribute getAttribute = new GetAttribute(); getAttribute.NewInstance(); availableBaseObjects.Add(getAttribute); GetHttpAuth getHttpAuth = new GetHttpAuth(); getHttpAuth.NewInstance(); availableBaseObjects.Add(getHttpAuth); GetImage getImage = new GetImage(); getImage.NewInstance(); availableBaseObjects.Add(getImage); GetJsPrompt getJsPrompt = new GetJsPrompt(); getJsPrompt.NewInstance(); availableBaseObjects.Add(getJsPrompt); GetStyle getStyle = new GetStyle(); getStyle.NewInstance(); availableBaseObjects.Add(getStyle); InvokeSubmit invokeSubmit = new InvokeSubmit(); invokeSubmit.NewInstance(); availableBaseObjects.Add(invokeSubmit); InvokeMouseClick invokeMouseClick = new InvokeMouseClick(); invokeMouseClick.NewInstance(); availableBaseObjects.Add(invokeMouseClick); JavascriptToExecute javascriptToExecute = new JavascriptToExecute(); javascriptToExecute.NewInstance(); availableBaseObjects.Add(javascriptToExecute); ResourceToLoad resourceToLoad = new ResourceToLoad(); resourceToLoad.NewInstance(); availableBaseObjects.Add(resourceToLoad); SetAttribute setAttribute = new SetAttribute(); setAttribute.NewInstance(); availableBaseObjects.Add(setAttribute); SetHttpAuth setHttpAuth = new SetHttpAuth(); setHttpAuth.NewInstance(); availableBaseObjects.Add(setHttpAuth); SetJsPrompt setJsPrompt = new SetJsPrompt(); setJsPrompt.NewInstance(); availableBaseObjects.Add(setJsPrompt); SetStyle setStyle = new SetStyle(); setStyle.NewInstance(); availableBaseObjects.Add(setStyle); SiteLoaded siteLoaded = new SiteLoaded(); siteLoaded.NewInstance(); availableBaseObjects.Add(siteLoaded); GetInnerText getInnerText = new GetInnerText(); getInnerText.NewInstance(); availableBaseObjects.Add(getInnerText); GetInnerHtml getInnerHtml = new GetInnerHtml(); getInnerHtml.NewInstance(); availableBaseObjects.Add(getInnerHtml); SetValue setValue = new SetValue(); setValue.NewInstance(); availableBaseObjects.Add(setValue); SecondsToWait secondsToWait = new SecondsToWait(); secondsToWait.NewInstance(); availableBaseObjects.Add(secondsToWait); InvokeFullKeyboardEvent invokeFullKeyBoardEvent = new InvokeFullKeyboardEvent(); invokeFullKeyBoardEvent.NewInstance(); availableBaseObjects.Add(invokeFullKeyBoardEvent); }
private void buttonCreateDemoTemplate_Click(object sender, EventArgs e) { List <TemplateElement> templateElements = new List <TemplateElement>(); SwitchWindowVisibility visibility = new SwitchWindowVisibility(); visibility.NewInstance(); visibility.Visible.Value = true; templateElements.Add(new TemplateElement("show window", visibility)); //Dont forget to change identifier to real one! LoadUrl url = new LoadUrl(); url.NewInstance(); url.Url.Value = "http://keepass.info/help/kb/testform.html"; templateElements.Add(new TemplateElement("Load Site", url)); BrowserAction actionLoaded = new BrowserAction(); SiteLoaded siteLoaded = new SiteLoaded(); siteLoaded.NewInstance(); siteLoaded.ExpectedSiteToLoad.Value = url.Url; siteLoaded.ExpectedSiteToLoad.IsRegex.Value = false; actionLoaded.ActionObject = siteLoaded; templateElements.Add(new TemplateElement("Check if Site has loaded", actionLoaded)); BrowserAction checkNumberOfElements1 = new CefBrowserControl.BrowserAction(); ElementToLoad loadElement = new ElementToLoad(); loadElement.NewInstance(); loadElement.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Id; loadElement.Selector.SelectorString = "LoginFormUser"; loadElement.Selector.ExpectedNumberOfElements = new InsecureInt(1); checkNumberOfElements1.ActionObject = loadElement; templateElements.Add(new TemplateElement("Check if Form exists", checkNumberOfElements1)); BrowserAction imageAction = new BrowserAction(); GetImage getImage1 = new GetImage(); getImage1.NewInstance(); imageAction.ActionObject = getImage1; getImage1.Selector.SelectorString = "/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[1]/img"; getImage1.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Xpath; TemplateElement getImageTemplateElement = new TemplateElement("Download KeePass Image", imageAction); templateElements.Add(getImageTemplateElement); GetInputFromUser input = new GetInputFromUser(); input.NewInstance(); input.InputNeeded.Value = true; input.InsecureDisplayObjects.Add(new InsecureText("Please type in 'OK'. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")); input.InsecureDisplayObjects.Add(new InsecureImage(Template.EncodeTemplateElementIdWithOutputName(getImageTemplateElement.UEID, GetImage.KeyList.Base64String.ToString()))); TemplateElement templateElement1 = new TemplateElement("Get OK from User", input); templateElement1.SuccessConditions.Add(new Condition("Contains", Template.EncodeTemplateElementIdWithOutputName("", GetInputFromUser.KeyList.UserInputResult.ToString()), "OK")); templateElements.Add(templateElement1); //---------------------------- BrowserAction checkNumberOfElements2 = new CefBrowserControl.BrowserAction(); ElementToLoad elementToLoad2 = new ElementToLoad(); elementToLoad2.NewInstance(); checkNumberOfElements2.ActionObject = elementToLoad2; elementToLoad2.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Name; elementToLoad2.Selector.SelectorString = "pwd"; elementToLoad2.Selector.ExpectedNumberOfElements.Value = 1; templateElements.Add(new TemplateElement("Check if Form Field 'pwd' exists", checkNumberOfElements2)); BrowserAction checkNumberOfElements3 = new CefBrowserControl.BrowserAction(); ElementToLoad elementToLoad3 = new ElementToLoad(); elementToLoad3.NewInstance(); checkNumberOfElements3.ActionObject = elementToLoad3; elementToLoad3.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Name; elementToLoad3.Selector.SelectorString = "LoginForm"; elementToLoad3.Selector.ExpectedNumberOfElements.Value = 1; templateElements.Add(new TemplateElement("Check if Form Field 'LoginForm' exists", checkNumberOfElements3)); BrowserAction enteryUserName = new BrowserAction(); SetAttribute setAttributeUserName = new SetAttribute(); setAttributeUserName.NewInstance(); enteryUserName.ActionObject = setAttributeUserName; setAttributeUserName.AttributeName.Value = "Value"; setAttributeUserName.ValueToSet.Value = BaseObject.ConvertStringToPlaceholderString(PwDefs.UserNameField); setAttributeUserName.Selector.ExpectedNumberOfElements.Value = 1; setAttributeUserName.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Id; setAttributeUserName.Selector.SelectorString = "LoginFormUser"; templateElements.Add(new TemplateElement("enter username", enteryUserName)); BrowserAction enterPassword = new BrowserAction(); SetAttribute setAttributePassword = new SetAttribute(); setAttributePassword.NewInstance(); enterPassword.ActionObject = setAttributePassword; setAttributePassword.AttributeName.Value = "Value"; setAttributePassword.ValueToSet.Value = BaseObject.ConvertStringToPlaceholderString(PwDefs.PasswordField) + " " + BaseObject.ConvertStringToPlaceholderString(""); setAttributePassword.Selector.ExpectedNumberOfElements.Value = 1; setAttributePassword.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Name; setAttributePassword.Selector.SelectorString = "pwd"; templateElements.Add(new TemplateElement("enter password", enterPassword)); BrowserAction handleJsDialog = new BrowserAction(); SetJsPrompt setJsPrompt = new SetJsPrompt(); setJsPrompt.NewInstance(); handleJsDialog.ActionObject = setJsPrompt; setJsPrompt.ExpectedDialogType.Value = GetJsPrompt.DialogTypes.Alert; setJsPrompt.ExpectedMessageText.IsRegex.Value = true; setJsPrompt.ExpectedMessageText.Value.Value = "The following data would have been submitted"; templateElements.Add(new TemplateElement("set jsdialog handler", handleJsDialog)); SwitchWindowVisibility visibility2 = new SwitchWindowVisibility(); visibility2.NewInstance(); visibility2.Visible.Value = false; templateElements.Add(new TemplateElement("hide window", visibility2)); BrowserAction clickSubmit = new BrowserAction(); InvokeSubmit invokeSubmit = new InvokeSubmit(); invokeSubmit.NewInstance(); clickSubmit.ActionObject = invokeSubmit; invokeSubmit.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Name; invokeSubmit.Selector.SelectorString = "LoginForm"; invokeSubmit.Selector.ExpectedNumberOfElements.Value = 1; templateElements.Add(new TemplateElement("submit form", clickSubmit)); BrowserAction checkJsDialog = new BrowserAction(); GetJsPrompt getJsPrompt = new GetJsPrompt(); getJsPrompt.NewInstance(); checkJsDialog.ActionObject = getJsPrompt; getJsPrompt.ExpectedDialogType.Value = GetJsPrompt.DialogTypes.Alert; getJsPrompt.ExpectedMessageText.IsRegex.Value = true; getJsPrompt.ExpectedMessageText.Value.Value = "The following data would have been submitted"; TemplateElement templateElement2 = new TemplateElement("get jsdialog", checkJsDialog); templateElement2.SuccessConditions.Add(new Condition("Contains", Template.EncodeTemplateElementIdWithOutputName("", GetJsPrompt.KeyList.MessageText.ToString()), "The following data would have been submitted")); templateElements.Add(templateElement2); Template template = new Template(1, new StringOrRegex() { IsRegex = new InsecureBool(true), Value = new InsecureText("keepass") }, "KeePass TestForm, some illegal chars: \"M\"\\a/ry/ h**ad:>> a\\/:*?\"| li*tt|le|| la\"mb.?", new PasswordCreationPolicy(), templateElements); AddTemplate(template); RefreshUI(); }
private void _timerBrowserHandling_Elapsed(object sender, ElapsedEventArgs e) { _timerBrowserHandling.Stop(); try { TimerCefBrowserLock.AcquireWriterLock(Options.LockTimeOut); try { CefListLock.AcquireWriterLock(Options.LockTimeOut); try { List <string> forRemoving = new List <string>(); foreach (var ucidToBrowsercommand in BrowserCommandsList) { try { string commandType = ucidToBrowsercommand.Value.GetType().Name; //Console.WriteLine(commandType); switch (commandType) { case "Open": Open open = (Open)ucidToBrowsercommand.Value; open.Successful = true; open.Completed = true; forRemoving.Add(open.UCID); break; case "SwitchWindowVisibility": SwitchWindowVisibility visibility = (SwitchWindowVisibility)ucidToBrowsercommand.Value; //Visibility = visibility.Visible.Value ? Visibility.Visible : Visibility.Hidden; //ShowInTaskbar = visibility.Visible.Value; Dispatcher.Invoke(() => { //Visibility = visibility.Visible.Value ? Visibility.Visible : Visibility.Hidden; //ShowInTaskbar = visibility.Visible.Value; if (visibility.Visible.Value) { Topmost = true; Activate(); Show(); } else { Topmost = false; Hide(); } }); visibility.Successful = true; visibility.Completed = true; forRemoving.Add(visibility.UCID); break; case "LoadUrl": LoadUrl loadUrl = (LoadUrl)ucidToBrowsercommand.Value; Dispatcher.Invoke(() => { Browser.Load(loadUrl.Url.Value); Title = loadUrl.Url.Value; }); loadUrl.Successful = true; loadUrl.Completed = true; forRemoving.Add(loadUrl.UCID); break; case "SwitchUserInputEnabling": SwitchUserInputEnabling enabling = (SwitchUserInputEnabling)ucidToBrowsercommand.Value; throw new Exception("This method is not fully implemented by CefBrowser"); // ReSharper disable once HeuristicUnreachableCode visibility.Completed = true; forRemoving.Add(visibility.UCID); break; case "GetInputFromUser": GetInputFromUser input = (GetInputFromUser)ucidToBrowsercommand.Value; Dispatcher.Invoke(() => { GetInput form = new GetInput((GetInputFromUser)ucidToBrowsercommand.Value); //form.Show(); }); while (true) { if (input.Completed || input.TimedOut) { break; } Thread.Sleep(100); } //form.Dispose(); //form = null; //input.Successful = true; input.Completed = true; forRemoving.Add(input.UCID); break; default: throw new Exception( "This browser command method is not implemented by CefBrowser"); } } catch (Exception ex) { ExceptionHandling.Handling.GetException("Unexpected", ex); } } foreach (string ucid in forRemoving) { BrowserCommandsCompleted.Add(ucid, BrowserCommandsList[ucid]); BrowserCommandsList.Remove(ucid); } //----BrowserActions forRemoving.Clear(); foreach (var ucidToBrowserAction in BrowserActionsList) { try { CefBrowserControl.BrowserAction browserAction = (CefBrowserControl.BrowserAction)ucidToBrowserAction.Value; ActionManager.AddBrowserActions(browserAction); forRemoving.Add(ucidToBrowserAction.Key); } catch (Exception ex) { ExceptionHandling.Handling.GetException("Unexpected", ex); } } foreach (string ucid in forRemoving) { //BrowserActionsCompleted.Add(ucid, BrowserActionsCompleted[ucid]); //BrowserActionsCompleted.Remove(ucid); BrowserActionsInTransit.Add(ucid, BrowserActionsList[ucid]); BrowserActionsList.Remove(ucid); } //get all completed actions from actionmanager forRemoving.Clear(); if (BrowserActionManager.BrowserActionsCompleted.Count > 0) { for (object obj = ActionManager.GetCompletedBrowserAction(); obj != null; obj = ActionManager.GetCompletedBrowserAction()) { CefBrowserControl.BrowserAction browserAction = (CefBrowserControl.BrowserAction)obj; forRemoving.Add(browserAction.UCID); } foreach (string ucid in forRemoving) { BrowserActionsCompleted.Add(ucid, BrowserActionsInTransit[ucid]); BrowserActionsInTransit.Remove(ucid); } } } catch (Exception ex) { ExceptionHandling.Handling.GetException("Unexpected", ex); } } catch (ApplicationException ex1) { ExceptionHandling.Handling.GetException("ReaderWriterLock", ex1); } finally { if (CefListLock.IsWriterLockHeld) { CefListLock.ReleaseWriterLock(); } } } catch (ApplicationException ex1) { ExceptionHandling.Handling.GetException("ReaderWriterLock", ex1); } finally { if (TimerCefBrowserLock.IsWriterLockHeld) { TimerCefBrowserLock.ReleaseWriterLock(); } _timerBrowserHandling.Start(); } }