SeleniumAssistant
When you require in the selenium-assistant
module an instance of this
SeleniumAssistant class will be returned.
This method gives you the require API's to manage downloading of browsers, accessing required browsers and making use of SaucesLabs.
Example
const seleniumAssistant = require('selenium-assistant');
const browsers = seleniumAssistant.getLocalBrowsers();
browsers.map(browser => {
console.log(browsers.getPrettyName());
console.log(browsers.getReleaseName());
return browser.getSeleniumDriver()
.then((driver) => {
return driver.get('https://google.com/')
.then(() => {
return seleniumAssistant.killWebDriver(driver);
});
});
});
Instance Methods
this.downloadLocalBrowser(browserId, release, expirationInHours) → Promise
This downloads a browser with browser ID of 'chrome' or 'firefox' and a release type of 'stable', 'beta', 'unstable'. SeleniumAssistant will download the browser and keep a track of when it was last downloaded.
The next time a download is requested, seleniumAssistant will check if the
browser is within the expirationInHours
parameter and if it is, resolve
the promise.
Any programs using selenium-assistant will share the same browser downloads reducing overall download time (unless setBrowserInstallDir() is called with a unique directory).
Example
return Promise.all([
seleniumAssistant.downloadLocalBrowser('chrome', 'stable', 48),
seleniumAssistant.downloadLocalBrowser('chrome', 'beta', 48),
seleniumAssistant.downloadLocalBrowser('chrome', 'unstable', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'stable', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'beta', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'unstable', 48),
])
.then(() => {
console.log('Browser download complete.');
})
.catch((err) => {
console.error('Browser download failed.');
});
Parameters |
|
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
Promise
The promise resolves once the browser has been downloaded. |
this.getBrowserInstallDir() → String
Returns the browser download path.
Returns |
String
Path of downloaded browsers |
---|
this.getLocalBrowser(browserId, release) → LocalBrowser
Most users of this library will want to make use of getLocalBrowsers to get all available browsers in the current environment.
If you need a specific browser use this method to retrieve it. Use LocalBrowser.isValid() to check if the browser is available on the current environment.
Parameters |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
LocalBrowser
A LocalBrowser instance that represents your request. |
this.getLocalBrowsers() → Array.<LocalBrowser>
This method returns a list of available browsers in the current environment.
This method will throw an error if run on a platform other than OS X and Linux.
Returns |
Array.<LocalBrowser>
Array of browsers discovered in the current environment. |
---|
this.getSauceLabsBrowser(browserId, browserVersion, options) → SauceLabsBrowser
Get a Sauce Labs hosted browser for a particular browser ID and a particular browser version.
Example
seleniumAssistant.setSaucelabsDetails(myusername, myaccesskey);
seleniumAssistant.startSaucelabsConnect()
.then(() => {
return seleniumAssistant.getSauceLabsBrowser('edge', 'latest');
})
.then((browserInstance) => {
return browserInstance.getSeleniumDriver();
})
.then((driver) => {
return driver.get('http://localhost:8080/')
.then(() => {
return seleniumAssistant.killWebDriver(driver);
});
})
.then(() => {
return seleniumAssistant.stopSaucelabsConnect();
});
Parameters |
|
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
SauceLabsBrowser
A selenium-assistant web driver instance. |
this.killWebDriver(driver) → Promise
Once a web driver is no longer needed, call this method to kill it.
This is a basic helper that adds a timeout to the end of killling the driver to account for shutdown time and the issues that can be caused if a new driver is launched too soon before the previous end of a driver.
Parameters |
|
|||||
---|---|---|---|---|---|---|
Returns |
Promise
Promise that resolves once the browser is killed. |
this.printAvailableBrowserInfo(printToConsole) → String
This method prints out a table of info for all available browsers on the current environment.
Useful if you are testing on Travis and want to see what tests should be running, but be cautious to print this only at the start of your tests to avoid excessive logging.
Parameters |
|
|||||
---|---|---|---|---|---|---|
Returns |
String
Returns table of information as a string. |
this.setBrowserInstallDir(newInstallDir)
To change where browsers are downloaded to, call this method before calling downloadLocalBrowser() and getLocalBrowsers().
By default, this will install under .selenium-assistant
in
your home directory on OS X and Linux, or just selenium-assistant
in your home directory on Windows.
Parameters |
|
---|
this.setSaucelabsDetails(username, accessKey)
If you wish to use Sauce Labs to host the browser instances you can do so by setting your saucelab details with this method before calling getSauceLabsBrowser().
Parameters |
|
---|
this.startSaucelabsConnect() → Promise
The Sauce Labs proxy allows a browser running on Sauce Labs to load a localhost site.
Calling this method will start the Sauce Labs connect proxy.
Returns |
Promise
Returns a promise that resolves once the proxy is set up. |
---|
this.stopSaucelabsConnect() → Promise
The Sauce Labs proxy allows a browser running on Sauce Labs to load a localhost site.
Calling this method will stop the Sauce Labs connect proxy.
Returns |
Promise
Returns a promise that resolves once the proxy is closed. |
---|