Exemple #1
0
        /// <summary>
        /// Clicks the on element., Just pass the basic name and the verification option switch will
        /// tag on Click on or Verify to the main test name, by default we are looking for xpath, but you can change that.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="name">The name.</param>
        /// <param name="fb">The fb.</param>
        /// <param name="verify">if set to <c>true</c> [verify].</param>
        /// <returns>List&lt;BatchCommandList&gt;.</returns>
        public static List <BatchCommandList> ClickOnElement(string element, string name,
                                                             GeneralActions.FindBy fb = GeneralActions.FindBy.XPath, bool verify = false)
        {
            List <BatchCommandList> cmd = new List <BatchCommandList>();

            GeneralActions.MyAction action = verify ? GeneralActions.MyAction.Nothing : GeneralActions.MyAction.Click;
            string testName = verify ? $"Verify {name}" : $"Click On {name}";

            cmd.Add(new BatchCommandList()
            {
                Actions     = action,
                UseCommand  = GeneralActions.UseCommand.WaitFound,
                ElementName = element,
                FindBy      = fb,
                TestName    = testName
            });
            return(cmd);
        }
Exemple #2
0
        /// <summary>
        /// Sets the text box.Just pass the basic name and the verification option switch will
        /// tag on Click on or Verify to the main test name, by default we are looking for xpath, but you can change that.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="name">The name.</param>
        /// <param name="newValue">The new value.</param>
        /// <param name="fb">The fb.</param>
        /// <param name="verify">if set to <c>true</c> [verify].</param>
        /// <returns>List&lt;BatchCommandList&gt;.</returns>
        public static List <BatchCommandList> SetTextBox(string element, string name, string newValue,
                                                         GeneralActions.FindBy fb = GeneralActions.FindBy.XPath, bool verify = false)
        {
            List <BatchCommandList> cmd = new List <BatchCommandList>();

            GeneralActions.MyAction action = verify ? GeneralActions.MyAction.Nothing : GeneralActions.MyAction.Click;
            string testName = verify ? $"Verify {name}" : $"Set {name} to {newValue}";

            cmd.Add(new BatchCommandList()
            {
                FindBy      = fb,
                Actions     = action,
                TestName    = testName,
                ElementName = element,
                UseCommand  = GeneralActions.UseCommand.WaitFound,
                SendKeys    = newValue
            });
            return(cmd);
        }
        /// <summary>
        /// Runs the selenium IDE file.
        /// </summary>
        /// <param name="useDriver">The use driver.</param>
        /// <param name="file">The file.</param>
        /// <param name="testName">Name of the test.</param>
        /// <param name="results">The results.</param>
        /// <param name="errOut">The error out.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        /// <exception cref="System.Exception">ERROR!  There is no url set in the file or was unable to pull it from teh json file!</exception>
        /// <exception cref="System.Exception"></exception>
        public static bool RunSeleniumIdeFile(FlexAction.UseDriver useDriver, string file, string testName, out string results, out string errOut)
        {
            bool bAns = false;

            errOut  = @"";
            results = @"";
            try
            {
                List <SideFile>         myCommands = ReadSeleniumIdeFile(file);
                List <BatchCommandList> bCmd       = new List <BatchCommandList>();

                string url = "";

                foreach (SideFile s in myCommands)
                {
                    url = s.url;
                    foreach (Test t in s.tests)
                    {
                        if (t.name.Equals(testName))
                        {
                            foreach (Command c in t.commands)
                            {
                                if (!c.command.Equals("open") && !c.command.Equals("setWindowSize") && !c.command.Equals("close"))
                                {
                                    string myTestName          = c.comment.Length == 0 ? $"{c.command} on {c.target}" : c.comment;
                                    string cmd                 = @"";
                                    string sendKeys            = c.value;
                                    GeneralActions.FindBy   fb = GeneralActions.FindBy.Id;
                                    GeneralActions.MyAction ma = GeneralActions.MyAction.Click;

                                    if (c.target.StartsWith("id="))
                                    {
                                        fb  = GeneralActions.FindBy.Id;
                                        cmd = c.target.Replace("id=", "");
                                    }
                                    else if (c.target.StartsWith("name="))
                                    {
                                        fb  = GeneralActions.FindBy.Name;
                                        cmd = c.target.Replace("name=", "");
                                    }
                                    else if (c.target.StartsWith("css="))
                                    {
                                        fb  = GeneralActions.FindBy.CssSelector;
                                        cmd = c.target.Replace("css=", "");
                                    }
                                    else if (c.target.StartsWith("xpath="))
                                    {
                                        fb  = GeneralActions.FindBy.XPath;
                                        cmd = c.target.Replace("xpath=", "");
                                    }
                                    else if (c.target.StartsWith("linkText="))
                                    {
                                        fb  = GeneralActions.FindBy.LinkText;
                                        cmd = c.target.Replace("linkText=", "");
                                    }

                                    switch (c.command)
                                    {
                                    case "click":
                                        ma = GeneralActions.MyAction.Click;
                                        break;

                                    case "type":
                                        ma = GeneralActions.MyAction.ClearSendKeys;
                                        break;

                                    case "sendKeys":
                                        ma = GeneralActions.MyAction.SendKeys;
                                        break;
                                        //case "":
                                        //    ma = GeneralActions.MyAction.Click;
                                        //    break;
                                        //case "":
                                        //    ma = GeneralActions.MyAction.Click;
                                        //    break;
                                        //case "":
                                        //    ma = GeneralActions.MyAction.Click;
                                        //    break;
                                    }

                                    bCmd.Add(new BatchCommandList()
                                    {
                                        TestName    = myTestName,
                                        FindBy      = fb,
                                        Actions     = ma,
                                        UseCommand  = GeneralActions.UseCommand.WaitFound,
                                        SendKeys    = sendKeys,
                                        ElementName = cmd
                                    });
                                }
                            }
                        }
                    }
                }
                if (url.Length == 0)
                {
                    throw new Exception("ERROR!  There is no url set in the file or was unable to pull it from teh json file!");
                }

                string settingsScreenShotLocation = "ExceptionShots";

                string fullExceptionPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, settingsScreenShotLocation);
                if (!Directory.Exists(fullExceptionPath))
                {
                    Directory.CreateDirectory(fullExceptionPath);
                }

                FlexAction sa = new FlexAction(useDriver);
                sa.DoSleep = true;
                sa.SettingsScreenShotLocation = fullExceptionPath;
                sa.Url      = url;
                sa.TestName = testName;
                sa.Initializer();
                List <BatchCommandList> myResults = sa.RunBatchCommands(bCmd, out errOut);
                results = sa.GenerateResults(myResults, out errOut);
                if (errOut?.Length > 0)
                {
                    throw new Exception(errOut);
                }
                bAns = sa.AllTestsPassed(myResults);
                sa.Close();
            }
            catch (Exception e)
            {
                errOut = e.Message;
            }
            return(bAns);
        }