本文整理汇总了TypeScript中selenium-webdriver.WebDriver类的典型用法代码示例。如果您正苦于以下问题:TypeScript WebDriver类的具体用法?TypeScript WebDriver怎么用?TypeScript WebDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebDriver类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: quitDriver
/**
* Quit a driver.
*
* @public
* @param webdriver instance
*/
quitDriver(driver: WebDriver): q.Promise<WebDriver> {
let driverIndex = this.drivers_.indexOf(driver);
if (driverIndex >= 0) {
this.drivers_.splice(driverIndex, 1);
}
let deferred = q.defer<WebDriver>();
if (driver.getSession() === undefined) {
deferred.resolve();
} else {
driver.getSession()
.then((session_: Session) => {
if (session_) {
driver.quit().then(function() {
deferred.resolve();
});
} else {
deferred.resolve();
}
})
.catch((err: Error) => {
deferred.resolve();
});
}
return deferred.promise;
}
示例2: getNewDriver
/**
* Getting a new driver by attaching an existing session.
*
* @public
* @return {WebDriver} webdriver instance
*/
getNewDriver(): WebDriver {
const httpClient = new http.HttpClient(this.config_.seleniumAddress);
const executor = new http.Executor(httpClient);
const newDriver = WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
this.drivers_.push(newDriver);
return newDriver;
}
示例3: BrowserError
let mappedDrivers = this.drivers_.map(async (driver: WebDriver) => {
let session = await driver.getSession();
// Fetching BrowserStack session details.
this.browserstackClient.getSession(
session.getId(), function(error: Error, automate_session: any) {
if (error) {
logger.info(
'BrowserStack results available at ' +
'https://www.browserstack.com/automate');
} else {
if (automate_session && automate_session.browser_url) {
logger.info('BrowserStack results available at ' + automate_session.browser_url);
} else {
logger.info(
'BrowserStack results available at ' +
'https://www.browserstack.com/automate');
}
}
});
let jobStatus = update.passed ? 'completed' : 'error';
let statusObj = {status: jobStatus};
// Updating status of BrowserStack session.
this.browserstackClient.updateSession(
session.getId(), statusObj, function(error: Error, automate_session: any) {
if (error) {
throw new BrowserError(
logger, 'Error updating BrowserStack pass/fail status: ' + util.inspect(error));
} else {
logger.info(automate_session);
}
});
});
示例4: getNewDriver
/**
* Getting a new driver by attaching an existing session.
*
* @public
* @return {WebDriver} webdriver instance
*/
getNewDriver(): webdriver.WebDriver {
var executor = executors.createExecutor(this.config_.seleniumAddress);
var newDriver = webdriver.WebDriver.attachToSession(
executor, this.config_.seleniumSessionId);
this.drivers_.push(newDriver);
return newDriver;
}
示例5: describe
describe('Google Search', () => {
let driver: WebDriver;
before(() => {
driver = new Builder().forBrowser('firefox').build();
});
beforeEach(() => { });
after(() => {
driver.quit();
});
afterEach(() => { });
it('should append query to title', () => {
const flow = controlFlow();
flow.execute(() => {
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
});
});
});
示例6: getNewDriver
/**
* Getting a new driver by attaching an existing session.
*
* @public
* @return {WebDriver} webdriver instance
*/
async getNewDriver(): Promise<WebDriver> {
const httpClient = new http.HttpClient(this.config_.seleniumAddress);
const executor = new http.Executor(httpClient);
const newDriver =
await WebDriver.attachToSession(executor, this.config_.seleniumSessionId, null);
this.drivers_.push(newDriver);
return newDriver;
}
示例7: Buffer
let deferredArray = this.drivers_.map((driver: WebDriver) => {
let deferred = q.defer();
driver.getSession().then((session: Session) => {
let headers: Object = {
'Content-Type': 'application/json',
'Authorization': 'Basic ' +
new Buffer(this.config_.browserstackUser + ':' + this.config_.browserstackKey)
.toString('base64')
};
let options = {
hostname: 'www.browserstack.com',
port: 443,
path: '/automate/sessions/' + session.getId() + '.json',
method: 'GET',
headers: headers
};
let req = https.request(options, (res) => {
res.on('data', (data: Buffer) => {
let info = JSON.parse(data.toString());
if (info && info.automation_session && info.automation_session.browser_url) {
logger.info(
'BrowserStack results available at ' + info.automation_session.browser_url);
} else {
logger.info(
'BrowserStack results available at ' +
'https://www.browserstack.com/automate');
}
});
});
req.end();
req.on('error', (e: Error) => {
logger.info(
'BrowserStack results available at ' +
'https://www.browserstack.com/automate');
});
let jobStatus = update.passed ? 'completed' : 'error';
options.method = 'PUT';
let update_req = https.request(options, (res) => {
let responseStr = '';
res.on('data', (data: Buffer) => {
responseStr += data.toString();
});
res.on('end', () => {
logger.info(responseStr);
deferred.resolve();
});
res.on('error', (e: Error) => {
throw new BrowserError(
logger, 'Error updating BrowserStack pass/fail status: ' + util.inspect(e));
});
});
update_req.write('{"status":"' + jobStatus + '"}');
update_req.end();
});
return deferred.promise;
});
示例8: verifyNoBrowserErrors
export async function verifyNoBrowserErrors() {
const browserLog = await browser.manage().logs().get('browser');
const collectedErrors: any[] = [];
browserLog.forEach(logEntry => {
const msg = logEntry.message;
// Since we currently use the `ts_devserver` from the Bazel TypeScript rules, which does
// fallback to the "index.html" file for HTML5 pushState routing but does always serve the
// expected fallback with a 404 status code, the browser will print a message about the 404,
// while the page loaded properly. Ideally the "ts_devserver" would allow us to opt-in for
// just returning a 200 status code, but the devserver is intended to be kept manually, so
// we manually filter this error before ensuring there are no console errors.
// TODO: This is a current limitation of using the "ts_devserver" with Angular routing.
// Tracked with: TOOL-629
if (msg.includes(
`Failed to load resource: the server responded with a status of 404 (Not Found)`)) {
return;
}
console.log('>> ' + msg, logEntry);
if (logEntry.level.value >= logging.Level.INFO.value) {
collectedErrors.push(msg);
}
});
expect(collectedErrors).toEqual([]);
}
示例9: RangeError
/**
* Executes a command which was defined by defineCommand()
*
* @param {string} name The command name.
* @param {*[]} params The parameters to the command
* @return {webdriver.promise.Promise<*>} A promise that will be resolved with
* the command result
*/
execCommand<T>(name: string, method: string, params: any[]): wdpromise.Promise<T> {
var paramNames = this.params_[method + ':' + name];
if (paramNames === undefined) {
throw new RangeError('The command "' + name + '" has not yet been defined');
}
if (paramNames.length !== params.length) {
throw new RangeError(
'The command "' + name + '" expected ' + paramNames.length + ' parameters, got ' +
params.length);
}
var command = new Command(name);
for (var i = 0; i < params.length; i++) {
if (params[i] !== undefined) {
command.setParameter(paramNames[i], params[i]);
}
}
return this.driver_.schedule(
command,
'Custom Command: ' + name + '(' +
params
.map((x: any) => {
if ((typeof x == 'number') || (typeof x == 'boolean') ||
(typeof x == 'function')) {
return x.toString();
} else if (x == null) {
return '' + x;
} else {
return JSON.stringify(x);
}
})
.join(', ') +
')');
}
示例10: checkContent
@AsyncTest("everyone gets a nice welcome")
public async checkContent() {
// get the wiki body
const title = await this._driver.findElement(By.id("wiki-body")).getText();
// check it contains what we'd expect
Expect(title).toContain("Welcome to the alsatian wiki!");
}