Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59845

Behat Stale Element reference failures

    XMLWordPrintable

    Details

      Description

      001 Scenario: Manager reopen a complete learning plan # /var/www/html/moodle/admin/tool/lp/tests/behat/plan_workflow.feature:183
            And I follow "Test-Plan4"                       # /var/www/html/moodle/admin/tool/lp/tests/behat/plan_workflow.feature:196
              WebDriver\Exception\StaleElementReference: Element is no longer attached to the DOM
              For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
              Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
              System info: host: 'e2718cfcc7c3', ip: '172.18.0.8', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.7.0_121'
              Driver info: driver.version: unknown in /var/www/html/moodle/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
              Stack trace:
              #0 /var/www/html/moodle/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php(140): WebDriver\Exception::factory(10, 'Element is no l...')
              #1 /var/www/html/moodle/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php(198): WebDriver\AbstractWebDriver->curl('POST', '/click', NULL)
              #2 /var/www/html/moodle/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php(218): WebDriver\AbstractWebDriver->__call('click', Array)
              #3 /var/www/html/moodle/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(748): WebDriver\Container->__call('click', Array)
              #4 /var/www/html/moodle/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(742): Behat\Mink\Driver\Selenium2Driver->clickOnElement(Object(WebDriver\Element))
              #5 /var/www/html/moodle/vendor/behat/mink/src/Element/NodeElement.php(153): Behat\Mink\Driver\Selenium2Driver->click('(//html/.//a\n[....')
              #6 /var/www/html/moodle/lib/tests/behat/behat_general.php(245): Behat\Mink\Element\NodeElement->click()
              #7 [internal function]: behat_general->click_link('Test-Plan4')
              #8 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(103): call_user_func_array(Array, Array)
              #9 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(59): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
              #10 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(140): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
              #11 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(96): Behat\Testwork\Call\CallCenter->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
              #12 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(125): Behat\Testwork\Call\CallCenter->makeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
              #13 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(73): Behat\Behat\Tester\Runtime\RuntimeStepTester->testDefinition(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), Object(Behat\Behat\Definition\SearchResult), false)
              #14 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableStepTester.php(74): Behat\Behat\Tester\Runtime\RuntimeStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
              #15 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/TickingStepTester.php(59): Behat\Behat\Hook\Tester\HookableStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
              #16 /var/www/html/moodle/vendor/moodlehq/behat-extension/src/Moodle/BehatExtension/EventDispatcher/Tester/ChainedStepTester.php(103): Behat\Behat\EventDispatcher\Tester\TickingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
              #17 /var/www/html/moodle/vendor/moodlehq/behat-extension/src/Moodle/BehatExtension/EventDispatcher/Tester/MoodleEventDispatchingStepTester.php(88): Moodle\BehatExtension\EventDispatcher\Tester\ChainedStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
              #18 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/StepContainerTester.php(59): Moodle\BehatExtension\EventDispatcher\Tester\MoodleEventDispatchingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
              #19 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeScenarioTester.php(76): Behat\Behat\Tester\StepContainerTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
              #20 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableScenarioTester.php(74): Behat\Behat\Tester\Runtime\RuntimeScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
              #21 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingScenarioTester.php(103): Behat\Behat\Hook\Tester\HookableScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
              #22 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/IsolatingScenarioTester.php(69): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
              #23 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeFeatureTester.php(84): Behat\Behat\Tester\Runtime\IsolatingScenarioTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
              #24 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableFeatureTester.php(72): Behat\Behat\Tester\Runtime\RuntimeFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
              #25 /var/www/html/moodle/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingFeatureTester.php(71): Behat\Behat\Hook\Tester\HookableFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
              #26 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeSuiteTester.php(63): Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
              #27 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Hook/Tester/HookableSuiteTester.php(73): Behat\Testwork\Tester\Runtime\RuntimeSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
              #28 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingSuiteTester.php(72): Behat\Testwork\Hook\Tester\HookableSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
              #29 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeExercise.php(71): Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
              #30 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
              #31 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
              #32 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(149): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
              #33 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
              #34 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Cli/Command.php(63): Behat\Testwork\Tester\Cli\ExerciseController->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #35 /var/www/html/moodle/vendor/symfony/console/Command/Command.php(262): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #36 /var/www/html/moodle/vendor/symfony/console/Application.php(826): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #37 /var/www/html/moodle/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #38 /var/www/html/moodle/vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #39 /var/www/html/moodle/vendor/symfony/console/Application.php(120): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
              #40 /var/www/html/moodle/vendor/behat/behat/bin/behat(34): Symfony\Component\Console\Application->run()
              #41 {main}
      

      The general consensus from Doctor Google is that this happens with poorly written tests.
      In our case, I believe it happens because we find an element, then we wait for a period, and then we click on it. During this time, the DOM may change and the element is now stale.

      https://stackoverflow.com/questions/5709204/random-element-is-no-longer-attached-to-the-dom-staleelementreferenceexception
      https://stackoverflow.com/questions/17174515/how-to-resolve-stale-element-exception-if-element-is-no-longer-attached-to-the

      The general advise seems to be to change the way in which we click on things so that we wait until it's visible before we find and click upon it, but I'm not sure if this is possible with our use of Selenium.

      Opening this issue so we have somewhere to keep track of failures.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  17/May/18