镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/client/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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 };
}
Expand Down
18 changes: 15 additions & 3 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/functional/fixtures/driver/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
@@ -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 () => {
});