diff --git a/src/client/browser/index.js b/src/client/browser/index.js index 16e0a5803f6..f3fd13c4737 100644 --- a/src/client/browser/index.js +++ b/src/client/browser/index.js @@ -104,17 +104,27 @@ export function stopInitScriptExecution () { allowInitScriptExecution = false; } -export function redirectUsingCdp (command, createXHR, openFileProtocolUrl) { +export function redirectUsingCdp (command, { openFileProtocolUrl, createXHR }) { sendXHR(openFileProtocolUrl, createXHR, { method: 'POST', data: JSON.stringify({ url: command.url }) }); //eslint-disable-line no-restricted-globals } -export function redirect (command, createXHR, openFileProtocolUrl) { +export function redirect (command, opts) { stopInitScriptExecution(); if (isFileProtocol(command.url)) - redirectUsingCdp(command, createXHR, openFileProtocolUrl); + redirectUsingCdp(command, opts); else - document.location = command.url; + setLocation(command, opts); +} + +function setLocation (command, opts) { + const hashIndex = command.url.indexOf('#'); + const onlyHashChanged = hashIndex !== -1 && command.url.slice(0, hashIndex) === LOCATION_HREF.slice(0, hashIndex); + + document.location = command.url; + + if (opts.nativeAutomation && onlyHashChanged) + document.location.reload(); } function nativeAutomationCheckRedirecting ({ result }) { @@ -136,7 +146,7 @@ async function getStatus ({ statusUrl, openFileProtocolUrl }, createXHR, { manua const redirecting = nativeAutomation ? nativeAutomationCheckRedirecting({ result }) : regularCheckRedirecting(result); if (redirecting && !manualRedirect) - redirect(result, createXHR, openFileProtocolUrl); + redirect(result, { createXHR, openFileProtocolUrl, nativeAutomation }); return { command: result, redirecting }; } diff --git a/src/client/driver/driver.js b/src/client/driver/driver.js index 32c058fe225..7a20f9b50e2 100644 --- a/src/client/driver/driver.js +++ b/src/client/driver/driver.js @@ -1268,8 +1268,14 @@ export default class Driver extends serviceUtils.EventEmitter { _onNavigateToCommand (command) { this.contextStorage.setItem(this.COMMAND_EXECUTING_FLAG, true); - if (this.options.nativeAutomation && isFileProtocol(command.url)) - browser.redirectUsingCdp(command, hammerhead.createNativeXHR, this.communicationUrls.openFileProtocolUrl); + if (this.options.nativeAutomation && isFileProtocol(command.url)) { + const redirectOpts = { + createXHR: hammerhead.createNativeXHR, + openFileProtocolUrl: this.communicationUrls.openFileProtocolUrl, + }; + + browser.redirectUsingCdp(command, redirectOpts); + } else { executeNavigateToCommand(command) .then(driverStatus => { @@ -1535,7 +1541,13 @@ export default class Driver extends serviceUtils.EventEmitter { storages.clear(); storages.lock(); - browser.redirect(command, hammerhead.createNativeXHR, this.communicationUrls.openFileProtocolUrl); + const redirectOpts = { + createXHR: hammerhead.createNativeXHR, + openFileProtocolUrl: this.communicationUrls.openFileProtocolUrl, + nativeAutomation: this.options.nativeAutomation, + }; + + browser.redirect(command, redirectOpts); } else { this.contextStorage.setItem(TEST_DONE_SENT_FLAG, false); diff --git a/test/functional/fixtures/driver/test.js b/test/functional/fixtures/driver/test.js index 6b691c26cd8..eca6f2ccd32 100644 --- a/test/functional/fixtures/driver/test.js +++ b/test/functional/fixtures/driver/test.js @@ -47,5 +47,9 @@ describe('TestRun - Driver protocol', function () { onlyInNativeAutomation('Should clear out the localStorage and sessionStorage for multiple domains(native automation)', function () { return runTests('./testcafe-fixtures/clear-and-lock-storages-native-automation-part-2.js'); }); + + it('Should force page reload if url has # in Native Automation', function () { + return runTests('./testcafe-fixtures/page-url-with-hash.js'); + }); }); }); diff --git a/test/functional/fixtures/driver/testcafe-fixtures/page-url-with-hash.js b/test/functional/fixtures/driver/testcafe-fixtures/page-url-with-hash.js new file mode 100644 index 00000000000..64ba0c5ddc1 --- /dev/null +++ b/test/functional/fixtures/driver/testcafe-fixtures/page-url-with-hash.js @@ -0,0 +1,13 @@ +fixture `Driver`; + +test.page('http://localhost:3000/fixtures/driver/pages/empty-page.html/#/')('Test 1', async () => { +}); + +test.page('http://localhost:3000/fixtures/driver/pages/empty-page.html/#/')('Test 2', async () => { +}); + +test.page('http://localhost:3000/fixtures/driver/pages/empty-page.html/#/test')('Test 3', async () => { +}); + +test.page('http://localhost:3000/fixtures/driver/pages/empty-page.html/#/')('Test 4', async () => { +});