Esempio n. 1
0
        int catchLimit = Settings.catchLimit; //do settingsów

        public string Operation(Structs.TestStep testStep1)
        {
            string result = "init";

            try
            {
                opActions.KeepMaximized(testStep1); //wielkość okna chrome, ważne dla niezawodności opetarions

                result = PerformOperation(testStep1);
                opActions.Sleep(Settings.sleepAfterOperation);
                catchCount = 0;
            }

            catch (NoAlertPresentException)
            {
                catchCount++;
                testStuff.Log("Exception caught \"NoAlertPresentException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: sleep, retry.");
                opActions.Sleep(200);
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    //result = "Catch limit exceeded: \"UnhandledAlertException\" in step " + testStep1.stepDescription + ".";
                    result = "ok"; //dziwne, ale chodzi o to, że kiedy leci taki wyjątek, to praktycznie zawsze przy próbie pozbycia się jebanego alertu; więc tu zakładany, że jebańca nie ma
                }
            }
            catch (UnhandledAlertException)
            {
                catchCount++;
                testStuff.Log("Exception caught \"UnhandledAlertException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: close alert, retry.");
                opActions.OpActionCloseAlert("Accept");
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded: \"UnhandledAlertException\" in step " + testStep1.stepDescription + ".";
                }
            }
            catch (StaleElementReferenceException)
            {
                catchCount++;
                testStuff.Log("Exception caught \"StaleElementReferenceException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: retry.");
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded: \"StaleElementReferenceException\" in step " + testStep1.stepDescription + ".";
                }
            }
            catch (ElementNotInteractableException)
            {
                catchCount++;
                testStuff.Log("Exception caught \"ElementNotInteractableException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: sleep, retry.");
                opActions.Sleep(Settings.sleepAfterElementNotInteractible);
                if (catchCount < catchLimit)
                {
                    if (Settings.allowTryHelps)
                    {
                        opActions.TryHelpNonInteractible(testStep1, catchCount); //znajduje interaktywnego rodzica i najeżdża na niego kursorem
                    }

                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded. \"ElementNotInteractableException\" in step " + testStep1.stepDescription + ".";
                }
            }
            //niby redundantne z implicit wait, ale w praktyce pomaga
            catch (NoSuchElementException e)
            {
                catchCount += 1;
                testStuff.Log("Exception caught \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry.");
                opActions.Sleep(Settings.sleepAfterNoSuchElement); //do tego dochodzi implicit wait, więc łącznie 40,3 s x 10... wtf

                if (catchCount < Settings.noSuchElementCatchLimit)
                {
                    if (Settings.allowTryHelps)
                    {
                        opActions.TryHelpNoSuchElement(catchCount); //scrolluje
                    }

                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded. \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Is test scenario up-to-date? Exception: \r\n" + e;
                }
            }
            catch (Exception e)
            {
                result = "Error in step named: \"" + testStep1.stepDescription + "\". Operation: \"" + testStep1.operationName + "\". Exception: \r\n" + e;
            }

            return(result);
        }
Esempio n. 2
0
        int catchLimit = Settings.catchLimit; //do settingsów

        public string Operation(Structs.TestStep testStep1)
        {
            string result = "init";

            try
            {
                opActions.KeepMaximized(testStep1); //wielkość okna chrome, ważne dla niezawodności opetarions

                result = PerformOperation(testStep1);
                opActions.Sleep(Settings.sleepAfterOperation);
                catchCount = 0;
            }
            catch (NoAlertPresentException)
            {
                catchCount++;
                testSetup.Log("Exception caught \"NoAlertPresentException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: none.");
            }
            catch (UnhandledAlertException)
            {
                catchCount++;
                testSetup.Log("Exception caught \"UnhandledAlertException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: close alert, retry.");
                opActions.OpActionCloseAlert("Accept");
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded: \"UnhandledAlertException\" in test step " + testStep1.stepDescription + ".";
                }
            }
            catch (StaleElementReferenceException)
            {
                catchCount++;
                testSetup.Log("Exception caught \"StaleElementReferenceException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next action: retry.");
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded: \"StaleElementReferenceException\" in test step " + testStep1.stepDescription + ".";
                }
            }
            catch (ElementNotInteractableException)
            {
                catchCount++;
                testSetup.Log("Exception caught \"ElementNotInteractableException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry.");
                opActions.Sleep(Settings.sleepAfterElementNotInteractible);
                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded. \"ElementNotInteractableException\" in test step " + testStep1.stepDescription + ".";
                }
            }
            //niby redundantne z implicit wait, ale w praktyce pomaga
            catch (NoSuchElementException e)
            {
                catchCount += 9; //ze względu na implicit wait (jakoś to ogarnąć potem)
                testSetup.Log("Exception caught \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry.");
                //bez refresh!
                opActions.Sleep(Settings.sleepAfterNoSuchElement); //do tego dochodzi implicit wait, więc łącznie 40,3 s x 10... wtf

                if (catchCount < catchLimit)
                {
                    result = Operation(testStep1);
                }
                else
                {
                    result = "Catch limit exceeded. \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Exception: \r\n" + e;
                }
            }
            catch (Exception e)
            {
                result = "Error in step named: \"" + testStep1.stepDescription + "\". Operation: \"" + testStep1.operationName + "\". Exception: \r\n" + e;
            }

            return(result);
        }