This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driverProvider): Add useExistingWebDriver driver provider (#4756)
- Loading branch information
Showing
7 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This is an implementation of the Use Existing WebDriver Driver Provider. | ||
* It is responsible for setting up the account object, tearing it down, and | ||
* setting up the driver correctly. | ||
*/ | ||
import * as q from 'q'; | ||
import {promise as wdpromise, WebDriver} from 'selenium-webdriver'; | ||
|
||
import {Config} from '../config'; | ||
import {Logger} from '../logger'; | ||
|
||
import {DriverProvider} from './driverProvider'; | ||
|
||
const http = require('selenium-webdriver/http'); | ||
|
||
let logger = new Logger('useExistingWebDriver'); | ||
|
||
export class UseExistingWebDriver extends DriverProvider { | ||
constructor(config: Config) { | ||
super(config); | ||
} | ||
|
||
/** | ||
* Configure and launch (if applicable) the object's environment. | ||
* @return {q.promise} A promise which will resolve when the environment is | ||
* ready to test. | ||
*/ | ||
protected setupDriverEnv(): q.Promise<any> { | ||
const defer = q.defer(); | ||
this.config_.seleniumWebDriver.getSession().then((session) => { | ||
logger.info('Using session id - ' + session.getId()); | ||
return defer.resolve(); | ||
}); | ||
return q(undefined); | ||
} | ||
|
||
/** | ||
* Getting a new driver by attaching an existing session. | ||
* | ||
* @public | ||
* @return {WebDriver} webdriver instance | ||
*/ | ||
getNewDriver(): WebDriver { | ||
const newDriver = this.config_.seleniumWebDriver; | ||
this.drivers_.push(newDriver); | ||
return newDriver; | ||
} | ||
|
||
/** | ||
* Maintains the existing session and does not quit the driver. | ||
* | ||
* @public | ||
*/ | ||
quitDriver(): wdpromise.Promise<void> { | ||
return wdpromise.when(undefined); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var env = require('./environment'); | ||
var webdriver = require('selenium-webdriver'); | ||
|
||
var existingDriver = new webdriver.Builder() | ||
.usingServer(env.seleniumAddress) | ||
.withCapabilities(env.capabilities) | ||
.build(); | ||
|
||
exports.config = { | ||
|
||
framework: 'jasmine', | ||
|
||
specs: [ | ||
'driverProviders/useExistingWebDriver/*_spec.js' | ||
], | ||
|
||
capabilities: env.capabilities, | ||
|
||
baseUrl: env.baseUrl, | ||
|
||
seleniumWebDriver: existingDriver, | ||
}; |
16 changes: 16 additions & 0 deletions
16
spec/driverProviders/useExistingWebDriver/useExistingDriver_spec.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,16 @@ | ||
describe('uses existing webdriver', function() { | ||
var URL = '/ng2/#/async'; | ||
|
||
beforeEach(function() { | ||
browser.get(URL); | ||
}); | ||
it('should be able to use an existing session', function() { | ||
var increment = $('#increment'); | ||
expect(increment).toBeDefined(); | ||
}); | ||
// the driverProvider is set up to ignore the quitDriver() call; | ||
// so we call quit() ourselves to tidy up when testing is done. | ||
afterEach(function() { | ||
browser.quit(); | ||
}); | ||
}); |