Skip to content
Snippets Groups Projects
Commit f3e76acd authored by Ray Schamp's avatar Ray Schamp
Browse files

Capture onbeforeunload unsetter in a helper

parent 145ade6f
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,8 @@ class SeleniumHelper {
'findByText',
'findByXpath',
'getDriver',
'getLogs'
'getLogs',
'loadUri'
]);
}
......@@ -34,6 +35,14 @@ class SeleniumHelper {
return this.findByXpath(`//body//${scope || '*'}//*[contains(text(), '${text}')]`);
}
loadUri (uri) {
return this.driver
.get(`file://${uri}`)
.then(() => (
this.driver.executeScript('window.onbeforeunload = undefined;')
));
}
clickXpath (xpath) {
return this.findByXpath(xpath).then(el => el.click());
}
......
......@@ -9,7 +9,8 @@ const {
clickXpath,
findByXpath,
getDriver,
getLogs
getLogs,
loadUri
} = new SeleniumHelper();
const errorWhitelist = [
......@@ -31,7 +32,7 @@ describe('player example', () => {
test('Load a project by ID', async () => {
const projectId = '96708228';
await driver.get(`file://${uri}#${projectId}`);
await loadUri(`${uri}#${projectId}`);
await new Promise(resolve => setTimeout(resolve, 2000));
await clickXpath('//img[@title="Go"]');
await new Promise(resolve => setTimeout(resolve, 2000));
......@@ -54,7 +55,7 @@ describe('blocks example', () => {
test('Load a project by ID', async () => {
const projectId = '96708228';
await driver.get(`file://${uri}#${projectId}`);
await loadUri(`${uri}#${projectId}`);
await new Promise(resolve => setTimeout(resolve, 2000));
await clickXpath('//img[@title="Go"]');
await new Promise(resolve => setTimeout(resolve, 2000));
......@@ -64,7 +65,7 @@ describe('blocks example', () => {
});
test('Change categories', async () => {
await driver.get(`file://${uri}`);
await loadUri(`${uri}`);
await clickText('Looks');
await clickText('Sound');
await clickText('Events');
......
......@@ -8,7 +8,8 @@ const {
findByText,
findByXpath,
getDriver,
getLogs
getLogs,
loadUri
} = new SeleniumHelper();
const uri = path.resolve(__dirname, '../../build/index.html');
......@@ -36,8 +37,7 @@ describe('costumes, sounds and variables', () => {
test('Blocks report when clicked in the toolbox', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Blocks');
await clickText('Operators', blocksTabScope);
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
......@@ -48,8 +48,7 @@ describe('costumes, sounds and variables', () => {
});
test('Switching sprites updates the block menus', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Sound', blocksTabScope);
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
// "meow" sound block should be visible
......@@ -62,8 +61,7 @@ describe('costumes, sounds and variables', () => {
});
test('Adding a costume', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Costumes');
await clickText('Add Costume');
const el = await findByXpath("//input[@placeholder='what are you looking for?']");
......@@ -76,8 +74,7 @@ describe('costumes, sounds and variables', () => {
});
test('Adding a sound', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Sounds');
await clickText('Add Sound');
const el = await findByXpath("//input[@placeholder='what are you looking for?']");
......@@ -103,8 +100,7 @@ describe('costumes, sounds and variables', () => {
test('Load a project by ID', async () => {
const projectId = '96708228';
await driver.get(`file://${uri}#${projectId}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(`${uri}#${projectId}`);
await new Promise(resolve => setTimeout(resolve, 2000));
await clickXpath('//img[@title="Go"]');
await new Promise(resolve => setTimeout(resolve, 2000));
......@@ -114,8 +110,7 @@ describe('costumes, sounds and variables', () => {
});
test('Creating variables', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Blocks');
await clickText('Data', blocksTabScope);
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
......@@ -139,8 +134,7 @@ describe('costumes, sounds and variables', () => {
});
test('Importing extensions', async () => {
await driver.get(`file://${uri}`);
await driver.executeScript('window.onbeforeunload = undefined;');
await loadUri(uri);
await clickText('Blocks');
await clickText('Extensions');
await clickText('Pen', modalScope); // Modal closes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment