Exemple #1
0
        private void Next_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.

            if (result == DialogResult.OK)                      // Test result.
            {
                filename = openFileDialog1.FileName;

                filePath.Text = filename;

                excelConnection = ExcelDataTools.GetTestDataFileConnection(filename);

                ExcelDataTools.PopulateWorkSheetCombo(excelConnection, cmbWorksheets);
            }
        }
        static public TestResults testEngine(List <TestDataObject> testData, List <ApplicationDataObject> applicationData, string environment, List <EnvironmentSettingsObject> environmentSettings, string username, string password, string browser, OleDbConnection excelConnection, string tab)

        //public void TestEngineClass()
        {
            IWebDriver driver;

            if (browser == "Internet Explorer")


            {
                string iEDriverLocation = GetDirectoryAppIsRunningIn() + iEDriverLocationRelativeToExecutionDirectory;

                var options = SetInternetExplorerDriverOptions();
                driver = new InternetExplorerDriver(iEDriverLocation, options);
            }
            else
            {
                string chromeDriverLocation = GetDirectoryAppIsRunningIn() + chromeDriverLocationRelativeToExecutionDirectory;
                driver = new ChromeDriver(chromeDriverLocation);
                // (@"C:\Users\dev_muldoons\Documents\Visual Studio 2015\Projects\AutomationTests\packages\WebDriver.IEDriver.32-bit.2.33.0\tools\");
            }
            //First lookup Data required and copy into currentTest object
            try
            {
                Thread th = Thread.CurrentThread;
                log.Info("Is Background = " + th.IsBackground.ToString());



                screenshotDirectory = CreateScreenShotDirectory();

                //IWebDriver driver = BrowserFactory.GetBrowser("IE");


                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
                driver.Manage().Window.Maximize();

                //driver.Navigate().GoToUrl(url);

                Stopwatch stopWatch = new Stopwatch();

                //driver.Navigate().GoToUrl(url);


                log.Info("created lafdata object with this many rows:" + testData.Count);
                log.Info("created applicationData object with this many rows:" + applicationData.Count);
                log.Info("created environmentSettings object with this many rows:" + environmentSettings.Count);



                //Find LAF Admin user for current environment

                //UserDataObject Admin = users.Find(item => item.User == "LAFAdmin" && item.Environment == environment);

                //Find LAF Admin URL for current environment

                EnvironmentSettingsObject currentEnvironment = environmentSettings.Find(item => item.Environment == environment);

                log.Info("currentEnvironment = " + currentEnvironment.Environment);

                log.Info("Admin URL = " + currentEnvironment.LAFAdminURL);

                //LAFSuperAdminEmail = LAFAdminUser;

                //LAFSuperAdminPassword = LAFAdminPW;



                LAFAdminURL = currentEnvironment.LAFAdminURL;

                int      numberSuccesses = 0;
                int      numberFailures  = 0;
                TimeSpan totaltime       = new TimeSpan(0);
                string   totalTimeString = "";

                foreach (var currentTest in testData)
                {
                    if (currentTest.ExecutionMode == "RUN")
                    {
                        //First move current run to previous run and ensure CurrentTest.Result is set to NULL (as this object has already been loaded so updating excel
                        //will not change this


                        ExcelDataTools.WriteToCell(currentTest.ID, "PreviousRun", currentTest.Result, tab, excelConnection);
                        ExcelDataTools.WriteToCell(currentTest.ID, "Result", "", tab, excelConnection);



                        currentTest.Result     = null;
                        currentTest.FailReason = null;
                        //First set test data for currentTest...


                        //Should surround with try / Catch with TEST DATA ERROR

                        //Add a try catch block around the data setup so can report in spreadsheet if there is a failure here as opposed to in test
                        try
                        {
                            currentTest.User   = username;
                            currentTest.UserPW = password;

                            thisApp = null;

                            if (!(currentTest.Application == null))
                            {
                                //convert to Call Method to call the below
                                thisApp = applicationData.Find(item => item.Application == currentTest.Application);
                                log.Info("app name from app settings = " + thisApp.Application);

                                //Will have to branch the following out into System, UAT,etc.. at some point...
                                //NEED TO REWORK NEXT BIT - NEEDS TO EXCLUDE WHEN NO RESULTS RETURNED
                            }
                        }
                        catch (Exception ex)
                        {
                            //Must be a test data failure, write to spreadsheet
                            log.Error("Failure in test data setup for this test case. Exception details = " + ex.ToString());
                            //ExcelDrivenFunctional.WriteToCell(currentTest.ID, "Test Data/Setup Failure - see application log for exception detail", "", "TestCases");
                        }
                        //Now do test
                        MethodInfo method;
                        string     elapsedTime = "N/A";
                        try
                        {
                            // Get MethodInfo.
                            Type type = typeof(Tests);
                            method = type.GetMethod(currentTest.TestMethodName);
                            if (method == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch
                        {
                            log.Error("Method does not exist (check spelling): " + currentTest.TestMethodName);
                            currentTest.Result     = "FAIL";
                            currentTest.FailReason = String.Format("Method with name {0} does not exist in Test Suite", currentTest.TestMethodName);
                            ExcelDataTools.WriteToCell(currentTest.ID, "Result", currentTest.Result, tab, excelConnection);
                            ExcelDataTools.WriteToCell(currentTest.ID, "FailReason", currentTest.FailReason, tab, excelConnection);
                            numberFailures++;

                            continue;
                            //break;
                        }



                        log.Info("before invoke, current test usergroupA = " + currentTest.userGroupA);



                        stopWatch.Restart();
                        //TestData currentTest, UserDataObject userData, EnvironmentSettingsObject environment, ApplicationDataObject appData,
                        try
                        {
                            method.Invoke(null, new object[] { currentTest, currentEnvironment, thisApp, driver });
                            //Some methods may record result as part of the test case, hence test if set first:
                            numberSuccesses++;
                            if (currentTest.Result == null)
                            {
                                currentTest.Result = "PASS";
                            }
                            log.Info("at end of catch block, current test result is = " + currentTest.Result);
                        }



                        catch (Exception ex)
                        {
                            if (thisApp.Application == null)
                            {
                                thisApp.Application = "LAF";
                            }
                            TakeScreenshot(driver, screenshotDirectory, currentTest.TestMethodName, currentTest.ID, thisApp.Application);
                            numberFailures++;

                            //Logout of LAF to ensure cleaned up for next Test

                            if (currentTest.Result == null)
                            {
                                currentTest.Result = "FAIL";
                            }
                            //currentTest.StackTrace = ex.ToString();
                            log.Info(ex.ToString());
                            log.Info("in catch block, current test result is = " + currentTest.Result);
                        }
                        stopWatch.Stop();
                        TimeSpan ts = stopWatch.Elapsed;

                        elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                    ts.Hours, ts.Minutes, ts.Seconds,
                                                    ts.Milliseconds / 10);
                        if (currentTest.Result == "PASS")
                        {
                            currentTest.FailReason = "N/A";
                        }
                        log.Info("In if passed block, current test result is = " + currentTest.Result);

                        ExcelDataTools.WriteToCell(currentTest.ID, "Result", currentTest.Result, tab, excelConnection);
                        log.Info("after writing result");
                        ExcelDataTools.WriteToCell(currentTest.ID, "ExecutionTime", elapsedTime, tab, excelConnection);
                        log.Info("after writing exec time");
                        ExcelDataTools.WriteToCell(currentTest.ID, "FailReason", currentTest.FailReason, tab, excelConnection);
                        log.Info("after writing fail reason");
                        //ExcelDrivenFunctional.WriteToCell(currentTest.ID, "StackTrace", currentTest.StackTrace, "TestCases");
                        log.Info("at end of test");
                        totaltime = totaltime + ts;

                        totalTimeString = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                    }
                }

                driver.Dispose();
                return(new TestResults(testData.Count, numberFailures, numberSuccesses, totalTimeString));
            }
            catch (Exception ex)
            {
                driver.Dispose();
                log.Error(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            /**LAFUserName = txtUserName.Text;
             * LAFPassword = txtPassword.Text;
             * Engine.TestEngine.TestEngineClass.testEngine(testData, users, applicationData, environment, environmentSettings, LAFUserName, LAFPassword);
             **/
            environment = comboEnvironment.Text;
            UserName    = txtUserName.Text;
            Password    = txtPassword.Text;
            browser     = cmbBrowser.Text;
            if (environment == "")
            {
                MessageBox.Show("You must select an environment before proceeding", "No environment selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (UserName == "")
            {
                MessageBox.Show("You must enter a Username before proceeding", "No username entered",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (Password == "")
            {
                MessageBox.Show("You must enter a Password before proceeding", "No password entered",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (browser == "")
            {
                MessageBox.Show("You must select a browser before proceeding", "No browser selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            DialogResult msgResult = new DialogResult();

            try
            {
                //Get Objects from Spreadsheet
                //TestSettingsObject testRunSettings = ExcelDrivenFunctional.GetTestRunSettings();



                testData = ExcelDataTools.GetTestData(excelConnection, tabName);



                applicationData     = ExcelDataTools.GetApplicationData(environment, excelConnection);
                environmentSettings = ExcelDataTools.GetEnvironmentSettings(environment, excelConnection);

                msgResult = MessageBox.Show("All Test Data loaded successfully. There are " + testData.Count + " tests specified to run in this suite. Click OK to begin", "Test data loaded successfully",
                                            MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

                if (msgResult.ToString() == "OK")
                {
                    msgResult = MessageBox.Show(String.Format("Before proceding, ensure that the input Excel file '{0}' is closed to ensure test results are correctly updated. When closed, click OK to proceed.", this.filename), "Ensure Excel file is closed",
                                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem reading input file - check format and content and try again.", "Could not load input file",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

            if (msgResult.ToString() == "OK")
            {
                try
                {
                    TestResults testResults = TestEngineClass.testEngine(testData, applicationData, environment, environmentSettings, UserName, Password, browser, excelConnection, tabName);

                    frmResults frmResults1 = new frmResults(testResults, browser, filename);
                    frmResults1.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unhandled Exception while running the test:\n\n\n\n " + ex.ToString(), "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }


                /**
                 * ThreadStart childref = new ThreadStart(StartExecutionThread);
                 * childThread = new Thread(childref);
                 * childThread.Start();
                 * //childThread.Join();
                 * TestResults testResults = new TestResults(5, 3, 2, "a long time");
                 * frmResults frmResults1 = new frmResults(testResults, "Chrome");
                 * frmResults1.Show();
                 *
                 **/
            }



            //this.Close();
        }