forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP]Restart browser if it became unresponsive (closes DevExpress#1815)
- Loading branch information
1 parent
19fd15d
commit 844c09a
Showing
7 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/functional/fixtures/browser-provider/browser-reconnect/pages/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
</body> | ||
</html> |
57 changes: 57 additions & 0 deletions
57
test/functional/fixtures/browser-provider/browser-reconnect/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const path = require('path'); | ||
const Promise = require('pinkie'); | ||
const expect = require('chai').expect; | ||
const config = require('../../../config'); | ||
const browserProviderPool = require('../../../../../lib/browser/provider/pool'); | ||
const BrowserConnection = require('../../../../../lib/browser/connection'); | ||
|
||
let hasErrors = true; | ||
|
||
function customReporter () { | ||
return { | ||
reportTestDone (name, testRunInfo) { | ||
hasErrors = !!testRunInfo.errs.length; | ||
}, | ||
reportFixtureStart () { | ||
}, | ||
reportTaskStart () { | ||
}, | ||
reportTaskDone () { | ||
} | ||
}; | ||
} | ||
|
||
if (config.useLocalBrowsers) { | ||
describe('Browser reconnect', function () { | ||
async function run (pathToTest) { | ||
const src = path.join(__dirname, pathToTest); | ||
const aliases = config.currentEnvironment.browsers.map(browser => browser.alias); | ||
|
||
return Promise.all(aliases.map(alias => browserProviderPool.getBrowserInfo(alias))) | ||
.then(browsers => { | ||
const connections = browsers.map(browser => new BrowserConnection(testCafe.browserConnectionGateway, browser, true)); | ||
|
||
connections.forEach(connection => { | ||
connection.HEARTBEAT_TIMEOUT = 4000; | ||
}); | ||
|
||
return connections; | ||
}) | ||
.then(connection => { | ||
return testCafe | ||
.createRunner() | ||
.src(src) | ||
.reporter(customReporter) | ||
.browsers(connection) | ||
.run().then(() => { | ||
expect(hasErrors).to.be.false; | ||
}); | ||
}); | ||
} | ||
|
||
it.only('Should restart browser when it does not respond', function () { | ||
return run('./testcafe-fixtures/index-test.js'); | ||
}); | ||
}); | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
test/functional/fixtures/browser-provider/browser-reconnect/testcafe-fixtures/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ClientFunction } from 'testcafe'; | ||
|
||
fixture `Browser reconnect` | ||
.page `http://localhost:3000/fixtures/browser-provider/browser-reconnect/pages/index.html`; | ||
|
||
const counter = {}; | ||
const getUserAgent = ClientFunction(() => navigator.userAgent.toString()); | ||
|
||
const hang = ClientFunction(() => { | ||
const now = Date.now(); | ||
|
||
while (Date.now() < now + 5000) { | ||
// hang for 5s | ||
} | ||
}); | ||
|
||
test('Should restart browser when it does not respond', async t => { | ||
const userAgent = await getUserAgent(); | ||
|
||
counter[userAgent] = counter[userAgent] || 0; | ||
|
||
counter[userAgent]++; | ||
|
||
if (counter[userAgent] < 3) | ||
await hang(); | ||
|
||
await t.expect(counter[userAgent]).eql(3); | ||
}); |