Skip to content

Commit

Permalink
Fix the "Cannot redefine property" error (closes #1996). (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMoskovkin authored and AndreyBelym committed Dec 14, 2017
1 parent 596d4b4 commit eade44d
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/client/automation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ exports.cursor = cursor;
exports.get = require;

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeAutomation%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: exports
});

Expand Down
4 changes: 1 addition & 3 deletions src/client/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ exports.selectorAttributeFilter = selectorAttributeFilter;
exports.get = require;

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeCore%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: exports
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeSel
}

return getNodeByIndex(filtered, options.index || 0);
}
},
configurable: true
});
16 changes: 4 additions & 12 deletions src/client/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,22 @@ import embeddingUtils from './embedding-utils';


hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeDriver%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: Driver
});

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeIframeDriver%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: IframeDriver
});

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%ScriptExecutionBarrier%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: ScriptExecutionBarrier
});

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeEmbeddingUtils%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: embeddingUtils
});

Expand Down
5 changes: 5 additions & 0 deletions src/client/test-run/iframe.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
});

driver.start();

Object.defineProperty(window, '%testCafeDriverInstance%', {
configurable: true,
value: driver
});
})();
4 changes: 1 addition & 3 deletions src/client/test-run/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
);

Object.defineProperty(window, '%testCafeDriverInstance%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: driver
});

Expand Down
4 changes: 1 addition & 3 deletions src/client/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ exports.show = function (showTopRoot) {
};

hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeUI%', {
enumerable: false,
configurable: false,
writable: false,
configurable: true,
value: exports
});

Expand Down
10 changes: 10 additions & 0 deletions test/functional/fixtures/regression/gh-1999/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>gh-1999</title>
</head>
<body>
<iframe id="iframe" src="javascript:'<html><body>Empty</body></html>'"></iframe>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-1999/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-1999)', function () {
it("Shouldn't raise an error if an iframe has html in src", function () {
return runTests('testcafe-fixtures/index.js', null, { only: 'chrome' });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fixture `GH-1999 - Shouldn't raise an error if an iframe has html in src`
.page `http://localhost:3000/fixtures/regression/gh-1999/pages/index.html`;

test('Click in iframe', async t => {
await t
.switchToIframe('#iframe')
.click('body');
});

0 comments on commit eade44d

Please sign in to comment.