🤖 Merge PR #63762 [nightwatchjs] Fix types of mobile-related commands. by @garg3133

This commit is contained in:
Priyansh Garg
2022-12-31 16:19:05 +05:30
committed by GitHub
parent ffec69009a
commit 57027e4fe1
2 changed files with 86 additions and 6 deletions

View File

@@ -6343,7 +6343,7 @@ export interface WebDriverProtocolMobileRelated {
*/
getOrientation(
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>) => void,
): this;
): Awaitable<this, 'LANDSCAPE' | 'PORTRAIT'>;
/**
* Sets the browser orientation.
@@ -6353,8 +6353,8 @@ export interface WebDriverProtocolMobileRelated {
*/
setOrientation(
orientation: 'LANDSCAPE' | 'PORTRAIT',
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void,
): this;
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<'LANDSCAPE' | 'PORTRAIT'>) => void,
): Awaitable<this, 'LANDSCAPE' | 'PORTRAIT'>;
/**
* Get a list of the available contexts.
@@ -6364,7 +6364,9 @@ export interface WebDriverProtocolMobileRelated {
*
* Used by Appium when testing hybrid mobile web apps. More info here: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/hybrid.md.
*/
contexts(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
contexts(
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string[]>) => void
): Awaitable<this, string[]>;
/**
* Get current context.
@@ -6372,7 +6374,9 @@ export interface WebDriverProtocolMobileRelated {
* @example
* browser.currentContext();
*/
currentContext(callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<any>) => void): this;
currentContext(
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<string | null>) => void
): Awaitable<this, string | null>;
/**
* Sets the context.
@@ -6380,7 +6384,10 @@ export interface WebDriverProtocolMobileRelated {
* @example
* browser.setContext(context);
*/
setContext(context: string, callback?: () => void): this;
setContext(
context: string,
callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<null>) => void
): Awaitable<this, null>;
}
/**

View File

@@ -131,6 +131,7 @@ const testGeneral: NightwatchTests = {
'test user defined globals': () => {
browser.url(`http://${browser.globals.username}:${browser.globals.password}@example.com`).end();
},
'Demo test for built-in API commands for working with the Chrome Devtools Protocol': () => {
// setGeolocation
browser
@@ -250,6 +251,78 @@ describe('duckduckgo example', function() {
});
});
//
// .tests/native/wikipedia.ts
//
const wikipediaAppTest: NightwatchTests = {
before: (client: NightwatchAPI) => {
client.click('xpath', '//XCUIElementTypeButton[@name="Skip"]');
},
'Search for BrowserStack': async (client: NightwatchAPI) => {
client
.useXpath()
.click('//XCUIElementTypeSearchField[@name="Search Wikipedia"]')
.getOrientation(function(result) {
if (result.status === 0) {
isType<'LANDSCAPE' | 'PORTRAIT'>(result.value);
}
isNightwatchAPI(this);
})
.setOrientation('LANDSCAPE', function(result) {
if (result.status === 0) {
isType<'LANDSCAPE' | 'PORTRAIT'>(result.value);
}
isNightwatchAPI(this);
})
.sendKeys('//XCUIElementTypeSearchField[@name="Search Wikipedia"]', 'browserstack')
.click('//XCUIElementTypeStaticText[@name="BrowserStack"]')
.waitUntil(async function() {
// wait for webview context to be available
const contexts = await client.contexts(function(result) {
if (result.status === 0) {
isType<string[]>(result.value);
}
isNightwatchAPI(this);
});
return contexts.length > 1;
}, 50000)
.perform(async function() {
// switch to webview context
const contexts = await client.contexts();
const setContextResult = await client.setContext(contexts[1], function(result) {
if (result.status === 0) {
isType<null>(result.value);
}
isNightwatchAPI(this);
});
const currContext = await client.currentContext(function(result) {
if (result.status === 0) {
isType<string | null>(result.value);
}
isNightwatchAPI(this);
});
isType<string[]>(contexts);
isType<null>(setContextResult);
isType<string | null>(currContext);
// switch orientation back to portrait
const currOrientation = await client.getOrientation();
const setOrientationResult = await client.setOrientation('PORTRAIT');
isType<'LANDSCAPE' | 'PORTRAIT'>(currOrientation);
isType<'LANDSCAPE' | 'PORTRAIT'>(setOrientationResult);
})
.useCss()
.assert.textEquals('.pcs-edit-section-title', 'BrowserStack'); // command run in webview context
client.end();
}
};
//
// ./pages/google.ts
//