Drush in Nightwatch tests can't detect the Simpletest site path
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3504045. --> Reported by: [murz](https://www.drupal.org/user/157092) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>I need to run drush commands from Nightwatch tests to interact with the test instance of Drupal.</p> <p>But when I just run the drush command, on the local setup it applies to the current website (installed locally), not to the instance created by the simpletest.</p> <p>And in the cloud CI, it just doesn't see the test database.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>1. Execute a drush command from a Nightwatch test, for example <code>drush cache:clear</code></p> <p>2. See that it doesn't use the simpletest site path, and fails on the database connection in CI, and locally - clears the cache of the local Drupal setup instead of the test instance's database.</p> <p>And here <a href="https://git.drupalcode.org/project/test_helpers/-/merge_requests/134">https://git.drupalcode.org/project/test_helpers/-/merge_requests/134</a> is a pipeline reproducing this issue.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>To resolve this, we should set the environment variable for <code>drush</code> with the simpletest site id, to make it know about the test website environment.</p> <p>Here is an example of how we can set it manually from the Nightwatch test context:</p> <pre>&nbsp; 'Run drush with ENV': (browser) =&gt; {<br>&nbsp;&nbsp;&nbsp; browser<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .drupalRelativeURL('/')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .perform(async () =&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const simpletestUserAgentCookieObject = await browser.cookies.get(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'SIMPLETEST_USER_AGENT',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const simpletestUserAgentCookie = decodeURIComponent(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; simpletestUserAgentCookieObject.value,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const drushCommand = `HTTP_USER_AGENT="${simpletestUserAgentCookie}" drush status`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; console.log(drushCommand);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const result = execSync(drushCommand);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; console.log(result.toString());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>&nbsp; },</pre><p>But it's better to make this from the pipeline scripts instead of this.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue