Example #1
0
 private void addCommandToGrid(Selenium_Test_Trinome cmd)
 {
     if (this.activeTestGrid.InvokeRequired == true)
     {
         addCommandToGridCallback d = new addCommandToGridCallback(addCommandToGrid);
         this.Invoke(d, new object[] { cmd });
     }
     else
     {
         this.activeTestGrid.Rows.Add(new string[] {
             cmd.getCommand(),
             cmd.getTarget(),
             cmd.getValue(),
             "",
             "",
             "",
             ""
         });
     }
 }
Example #2
0
        public ArrayList getTestCommands(String testFile)
        {
            ArrayList testCommands = new ArrayList();

            // this.log.message("testFile: " + testFile);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

            doc.OptionFixNestedTags = true;

            doc.Load(testFile);

            if (doc.ParseErrors != null && doc.ParseErrors.Count() > 0)
            {
                return testCommands;
            }

            int commandId = 0;

            foreach (HtmlNode testCommandRow in doc.DocumentNode.SelectNodes("/html/body/table/tbody"))
            {
                foreach (HtmlNode testNode in testCommandRow.ChildNodes)
                {
                    if (testNode.Name == "#comment")
                    {
                        Selenium_Test_Trinome triNome = new Selenium_Test_Trinome();
                        triNome.setCommand(":comment:");
                        String comment = System.Web.HttpUtility.HtmlDecode(testNode.InnerText);
                        comment = comment.Replace("<!-- ", "");
                        comment = comment.Replace(" -->", "");
                        triNome.setTarget(comment);
                        commandId++;
                        triNome.setId(commandId);
                        testCommands.Add(triNome);
                    }
                    if (testNode.Name == "tr")
                    {
                        Selenium_Test_Trinome triNome = new Selenium_Test_Trinome();
                        int tri = 0;
                        foreach (HtmlNode testTrinome in testNode.ChildNodes)
                        {
                            if (testTrinome.Name == "td")
                            {
                                tri++;

                                if (tri == 1)
                                {
                                    triNome.setCommand(testTrinome.InnerHtml);
                                }
                                if (tri == 2)
                                {
                                    triNome.setTarget(System.Web.HttpUtility.HtmlDecode(testTrinome.InnerHtml));
                                }
                                if (tri == 3)
                                {
                                    triNome.setValue(System.Web.HttpUtility.HtmlDecode(testTrinome.InnerHtml));
                                }
                            }
                        }

                        commandId++;
                        triNome.setId(commandId);

                        testCommands.Add(triNome);

                    }
                }

            }

            return testCommands;
        }
Example #3
0
        public Boolean processSelenese(Selenium_Test_Trinome testCommand, int testCmdCnt)
        {
            DateTime startTime = System.DateTime.UtcNow;
            DateTime stopTime = System.DateTime.UtcNow;

            if (testCommand.getCommand() == ":comment:")
            {
                this.updateCommandStatus(testCommand.getId(), 1, startTime, stopTime, "");
                return true;
            }

            if (this.testHadError == true)
            {
                this.updateCommandStatus(testCommand.getId(), 0, startTime, stopTime, "Command not executed: Failure already occurred");
                return false;
            }

            if (this.seleneseMethods.ContainsKey(testCommand.getCommand()))
            {
                SeleneseCommand cmd = (SeleneseCommand)this.seleneseMethods[testCommand.getCommand()];

                testCommand.interpolateSeleneseVariables(this.webDriver, this.testVariables);

                // Found the command in the vendor commands.
                String[] args;

                if (testCommand.getTarget().Length > 0 && testCommand.getValue().Length > 0)
                {
                    args = new String[2];
                    args[0] = testCommand.getTarget();
                    args[1] = testCommand.getValue();
                }
                else if (testCommand.getTarget().Length > 0)
                {
                    args = new String[1];
                    args[0] = testCommand.getTarget();
                }
                else
                {
                    args = null;
                }

                String message = "Working...";

                this.updateCommandStatus(testCommand.getId(), -1, startTime, stopTime, message);

                try
                {
                    DateTime s1 = System.DateTime.UtcNow;
                    cmd.Apply(this.webDriver, args);
                    DateTime s2 = System.DateTime.UtcNow;

                    stopTime = System.DateTime.UtcNow;
                    this.updateCommandStatus(testCommand.getId(), 1, startTime, stopTime, "");

                    this.waitForNextCommandTarget(testCommand, testCmdCnt, startTime, stopTime);

                    return true;
                }
                catch (Exception e)
                {
                    message = "failed: " + e.Message + " stacktrace: " + e.StackTrace.ToString();
                    stopTime = System.DateTime.UtcNow;
                    this.updateCommandStatus(testCommand.getId(), 0, startTime, stopTime, message);
                    this.testHadError = true;
                    return false;
                }
            }

            this.testHadError = true;
            this.updateCommandStatus(testCommand.getId(), 0, startTime, stopTime, "Command not executed: Unimplemented selenese.");
            return false;
        }
Example #4
0
        private void waitForNextCommandTarget(Selenium_Test_Trinome testCommand, int testCmdCnt, DateTime startTime, DateTime stopTime)
        {
            CTM_PageLoadWaiter pageLoad = new CTM_PageLoadWaiter(this.webDriver, 30000);

            ArrayList blockingCommands = new ArrayList();
            blockingCommands.Add("click");
            blockingCommands.Add("clickAndWait");
            blockingCommands.Add("open");

            ArrayList nextCommandLimiters = new ArrayList();
            nextCommandLimiters.Add("open");
            nextCommandLimiters.Add("verifySelectedLabel");
            nextCommandLimiters.Add("waitForPageToLoad"); // This is somewhat implicit with our new design.

            if (blockingCommands.Contains(testCommand.getCommand()))
            {

                // Find the next valid command.
                Selenium_Test_Trinome nextCommand = this.findNextTestCommand(testCmdCnt);

                // Set the wait timeout limit to 300s which is the default selenium timeout too.
                int waitTimeout = 300;

                // JEO: Pretty sure we need to limit this here to type and other commands
                if (nextCommand != null && nextCommandLimiters.Contains(nextCommand.getCommand()) == false)
                {
                    nextCommand.interpolateSeleneseVariables(this.webDriver,this.testVariables);

                    if (nextCommand.getTarget().Contains("${") == true || nextCommand.getValue().Contains("${") == true)
                    {
                        // Okay we're most likely in a logic loop here where a store command happenes before
                        // a use of the variable.
                        return;
                    }

                    if (nextCommand.getCommand() == "store" ) {
                        return;
                    }

                    double waitedSeconds = this.waitedSeconds(startTime, stopTime);

                    while( waitedSeconds < waitTimeout ) {

                        if (waitedSeconds > 60)
                        {

                        }

                        stopTime = System.DateTime.UtcNow;
                        waitedSeconds = this.waitedSeconds(startTime, stopTime);

                        this.updateCommandStatus(testCommand.getId(), 1, startTime, stopTime, "Waiting for next target..");

                        try
                        {
                            if (nextCommand.getCommand() == "verifyTextPresent" || nextCommand.getCommand() == "assertTextPresent")
                            {
                                String[] args = new String[2];
                                args[0] = nextCommand.getTarget();
                                args[1] = "";

                                CTM_IsTextPresent textPresentCmd = new CTM_IsTextPresent();

                                if ( (bool) textPresentCmd.Apply(this.webDriver, args) == true ) {
                                    stopTime = System.DateTime.UtcNow;
                                    this.updateCommandStatus(testCommand.getId(), 1, startTime, stopTime, "");
                                    return;
                                }

                            }
                            else
                            {
                                IWebElement elem = this.elementFinder.FindElement(this.webDriver, nextCommand.getTarget());
                                if (elem != null)
                                {

                                    stopTime = System.DateTime.UtcNow;
                                    this.updateCommandStatus(testCommand.getId(), 1, startTime, stopTime, "");
                                    return;
                                }
                            }

                            System.Threading.Thread.Sleep(1000);

                        }
                        catch
                        {
                            // It's okay if this fails we won't do anyting with it anyways.
                        }

                    }

                    stopTime = System.DateTime.UtcNow;
                    this.updateCommandStatus(testCommand.getId(), 0, startTime, stopTime, "Failed to find the next element within a acceptable time period. We waited " + waitedSeconds + "  seconds for nextCommand.Target: " + nextCommand.getTarget());
                    this.testHadError = true;
                    return;

                } // Skinning the cat differntly by avoiding the use of waiter()

            }

            return;
        }