mcdcorp / opentest

Open source test automation tool for web applications, mobile apps and APIs
https://getopentest.org
MIT License
447 stars 107 forks source link

selenium.NavigateTo url argument not refreshed when running tests based on same macro #509

Closed galegor closed 2 years ago

galegor commented 3 years ago

Releated to: opentest@beta Build: 1.3.1 Aug 25, 21:00 Commit: 971fb2982726

Hi @adrianth, I hope you are doing well. I was experimenting with $session.currentTestName and have found a problem most likely related to clearing selenium config after test run. So, the value of url property in below code snippet is not used as per actual config. Innstead, data related to the first test is used in both. If you run one of the tests separately then the correct site will be opened (all good here), but if you will create a session with both files then only the first url will be used twice.

To reproduce please use this simple code and configuration. data/myConfig.yaml

GH:
  url: https://github.com/mcdcorp

GO:
  url: https://www.google.com/

tests/GH_open.yaml

description: test
actors:
  - actor: WEB
    segments:
      - segment: 1
        actions:
          - macro: openSite

tests/GO_open.yaml

description: test
actors:
  - actor: WEB
    segments:
      - segment: 1
        actions:
          - macro: openSite

macros/openSite.yaml

description: Open site as per file name
actions:

  - description: set url based on current test name
    script: |
          var tag = $session.currentTestName.substring(0, 2);
          $log.trace("tag taken from a file/test name: " + tag);
          $localData.url = $data("myConfig")[tag].url;
          $log.trace("url taken from a config based on tag: " + $localData.url);

  - description: Navigate to url
    action: org.getopentest.selenium.NavigateTo
    args:
      url: $localData.url

  - description: wait a bit 
    script: |
      $delay(3000);

Sample log:

Timestamp   Actor   Message
18:44:20        
Sync server version: 1.3.1 2021-08-25 14:00:28 -0500 971fb2982726bf67d9ebb0d61b8ee46417c22743
18:44:20        
Acquiring actors for session 1630687461: WEB
18:44:20        
Session 1630687461 with label "Session 1630686303 6" started at 2021-09-03 16:44:20 UTC
18:44:25    WEB 
Actor 1117 of type WEB was acquired by test session 1630687461
18:44:25    WEB 
WARN: Failed to log extension JARs
18:44:25    WEB 
TRACE: Firing SESSION_STARTED event...
18:44:25    WEB 
==================== WEB: GH_open ====================
18:44:25    WEB 
Actor WEB started executing test GH_open...
18:44:25    WEB 
TRACE: Firing TEST_STARTED event...
18:44:25    WEB 
Executing segment 1 of test /GH_open...
18:44:25    WEB 
Evaluating action 1/1 (openSite) in segment 1...
18:44:25    WEB 
Executing macro openSite (no arguments were provided)...
18:44:25    WEB 
Evaluating action 1/3 in macro openSite (set url based on current test name)...
18:44:25    WEB 
TRACE: Initializing action org.getopentest.base.ScriptAction...
18:44:25    WEB 
Executing action org.getopentest.base.ScriptAction (no arguments were provided)...
18:44:25    WEB 
TRACE: tag taken from a file/test name: GH
18:44:25    WEB 
TRACE: url taken from a config based on tag: https://github.com/mcdcorp
18:44:25    WEB 
Evaluating action 2/3 in macro openSite (Navigate to url)...
18:44:25    WEB 
TRACE: Initializing action org.getopentest.selenium.NavigateTo...
18:44:25    WEB 
Using local Selenium server
18:44:25    WEB 
TRACE: Setting system property "webdriver.chrome.driver" to "C:/Selenium/chromedriver.exe"
18:44:26    WEB 
Executing action org.getopentest.selenium.NavigateTo with arguments {"url":"https://github.com/mcdcorp"}...
18:44:28    WEB 
Evaluating action 3/3 in macro openSite (wait 5s)...
18:44:28    WEB 
TRACE: Initializing action org.getopentest.base.ScriptAction...
18:44:28    WEB 
Executing action org.getopentest.base.ScriptAction (no arguments were provided)...
18:44:34    WEB 
TRACE: Firing TEST_COMPLETED event...
18:44:35    WEB 
==================== WEB: GO_open ====================
18:44:35    WEB 
Actor WEB started executing test GO_open...
18:44:35    WEB 
TRACE: Firing TEST_STARTED event...
18:44:35    WEB 
Executing segment 1 of test /GO_open...
18:44:35    WEB 
Evaluating action 1/1 (openSite) in segment 1...
18:44:35    WEB 
Executing macro openSite (no arguments were provided)...
18:44:35    WEB 
Evaluating action 1/3 in macro openSite (set url based on current test name)...
18:44:35    WEB 
TRACE: Initializing action org.getopentest.base.ScriptAction...
18:44:35    WEB 
Executing action org.getopentest.base.ScriptAction (no arguments were provided)...
18:44:35    WEB 
TRACE: tag taken from a file/test name: GO
18:44:35    WEB 
TRACE: url taken from a config based on tag: https://www.google.com/     <--------notice url here 
18:44:35    WEB 
Evaluating action 2/3 in macro openSite (Navigate to url)...
18:44:35    WEB 
TRACE: Initializing action org.getopentest.selenium.NavigateTo...
18:44:35    WEB 
Using local Selenium server
18:44:35    WEB 
TRACE: Setting system property "webdriver.chrome.driver" to "C:/Selenium/chromedriver.exe"
18:44:36    WEB 
Executing action org.getopentest.selenium.NavigateTo with arguments {"url":"https://github.com/mcdcorp"}...   
 <--------notice url here 
18:44:38    WEB 
Evaluating action 3/3 in macro openSite (wait 5s)...
18:44:38    WEB 
TRACE: Initializing action org.getopentest.base.ScriptAction...
18:44:38    WEB 
Executing action org.getopentest.base.ScriptAction (no arguments were provided)...
18:44:43    WEB 
Test session has completed
18:44:43    WEB 
TRACE: Firing TEST_COMPLETED event...
18:44:44    WEB 
TRACE: Firing SESSION_COMPLETED event...
18:44:44    WEB 
Actor 1117 of type WEB with tag(s) [localhost] is waiting to be acquired by a test session...
adrianth commented 3 years ago

Hi @galegor, thank you for the very detailed bug report - it allowed me to find and correct the issue very quickly. This bug was introduced due to a performance improvement, basically macro actions are cached on the actor side so that they only need to be requested from the server the very first time they are used for the duration of a test session.

Let me know if you need this fix fast and I might be able to publish a new release during the weekend or early next week.

galegor commented 3 years ago

If you would be able to release that bugfix to the beta at some point next week it will be helpful, thanks. When you are planing 1.3.1 to go live? I'm in the process of major refactoring which is based on the new goodies added in this one.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.