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();
        }
Exemplo n.º 2
0
        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);
        }