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
feat(driverProvider): Add useExistingWebDriver driver provider #4756
Merged
qiyigg
merged 1 commit into
angular:master
from
andyjack:andyjack/use-existing-webdriver
Aug 16, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for a simple question, but why you can not use
async ... await
construction instead ofq
library?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly copied the code from another driver provider, but I could redo my PR with
async/await
if that helps it getting merged. I don't exactly know what the house rules are for protractor code but I didn't see anything prohibitingq
, fwiw.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The driver providers were written before Promise was available in Node.js.
Probably it's fine to use async/await for new driver provider, but I am not sure whether it will just work since some other folks tried to refactor them using regular promise, but it turns out not easy. Since all the other driver providers are using q promise, I am also ok with q promise for this one.