Selenium-Chromedriver test execution leaves scoped_dir* temp files which makes test execution on an internal website to return 500 error

天涯浪子 提交于 2021-01-29 08:07:16

问题


We have Selenium-C# automation tests running an internal web application that requires an Outh-2 Bearer token. When I run the tests, set of temp files named scope_dir are created. These files get deleted automatically for some tests. But at some time during the test execution, they just remain without being deleted. After, this point, I receive a 500 error response.

I have tried the following:

Chromedriver not deleting scoped* dir in temp folder after test is complete

https://bugs.chromium.org/p/chromedriver/issues/detail?id=644

https://sqa.stackexchange.com/questions/26675/chromedriver-not-deleting-scoped-dir-in-temp-folder-after-test-is-complete

Failed to read HKLM\SOFTWARE\Policies\Google\Chrome\MachineLevelUserCloudPolicyEnrollmentToken: The system cannot find the file specified. (0x2)

https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/303

I drilled down into that scope_dir folder and found the following error:

[0111/171553.822:INFO:CONSOLE(21)] "BSSO Telemetry: >>{"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension: Extension is not installed."]}", source: https://aadcdn.msauth.net/ests/2.1.8438.15/content/cdnbundles/oldbssointerrupt_core.min_lg-ochofcwm0-pkfjghldq2.js (21) [0111/171553.878:INFO:CONSOLE(21)] "BSSO Telemetry: {"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension: Extension is not installed."]}", source: https://aadcdn.msftauth.net/ests/2.1.8438.15/content/cdnbundles/oldbssointerrupt_core.min_lg-ochofcwm0-pkfjghldq2.js (21) [0111/171553.897:INFO:CONSOLE(21)] "BSSO Telemetry: {"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension: Extension is not installed."]}", [0111/171605.329:INFO:CONSOLE(92679)] "Could not find HammerJS. Certain Angular Material components may not work correctly.", source: https://myWebsite.europe.cloudapp.azure.com/vendor.js (92679) [0111/171605.409:INFO:CONSOLE(636)] "Token: null", source:

One of the solution from above links was to delete the scope_dir folders before every test execution, when a test-suite is run. But, the problem is we run four test threads in parallel. Hence, deleting the scope_dir folder stomps on a running chromedriver.exe process causing issues.

Tests are run in Parallel using:

Google Chrome Version 71.0.3578.98

ChromeDriver version 2.45.6

Running tests through Specflow. Initially, our website was hosted in Azure App services, and test execution was smooth. But, for the past couple of weeks, it is being hosted in Service fabric. After this, we were experiencing this problem(However, not sure if this is the problem).


回答1:


You saw it right. When you run the Selenium/ChromeDriver based tests everytime a scoped_dir* is created while launching Chrome which is evident from the following log:

[1547372435.413][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-extensions --disable-extensions-except="C:\Users\ATECHM~1\AppData\Local\Temp\scoped_dir4616_4705\internal" --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=0 --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\ATECHM~1\AppData\Local\Temp\scoped_dir4616_1359" data:,

This scoped_dir* is required to pass the default/mandatory/configured arguments to initiate Chrome Browser. As an example:

"chrome": {
      "chromedriverVersion": "2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387)",
      "userDataDir": "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\scoped_dir4616_1359"
   }

But on successful invocation of driver.quit() at the end i.e. on clean exit, this temporary folder should get deleted by the ChromeDriver.

As per ChromeDriver does not delete the profile & scoped_dir* folders after test exits this issue was reproducible with ChromeDriver v2.28 and Browser: Chrome 57.x where @johnchen@chromium.org mentioned:

This appears to be a race condition between ChromeDriver and Chrome. ChromeDriver creates these temp directories for use by Chrome, and at the end ChromeDriver tries to delete those directories. ChromeDriver waits for the main Chrome process to terminate before doing the deletion, but some Chrome child processes might still be running and holding on to those directories, causing the deletion to fail. Currently ChromeDriver doesn't retry the deletion. Adding some retries might be the easiest fix.

This commit Chromedriver - Retry deleting temp dir when needed added the retry logic while cleaning up these directories incase ChromeDriver fails to delete temporary directories while exiting, causing wasted disk space. This fix was part of ChromeDriver 2.30.

Incase you are still seeing scoped_dir* (incase of parallel tests) you can store the userDataDir from Returned Capabilities and delete that folder. This cleans up the scoped_dir folder for that specific instance and helps when running parallel tests.



来源:https://stackoverflow.com/questions/54151695/selenium-chromedriver-test-execution-leaves-scoped-dir-temp-files-which-makes-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!