The authorizeSelenium
function uses the client
object to navigate to a provided auth URL, log in using the loginGoogle
function, and interact with various HTML elements on the page to retrieve the value of a textarea element.
npm run import -- "use selenium to authorize Google access"
var loginGoogle = importer.import("log in google");
function authorizeSelenium(authUrl) {
return client
.url(authUrl)
.then(() => loginGoogle(client))
.then(() => client.$('#submit_approve_access'))
.then(el => el.waitForDisplayed(3000))
.then(() => client.$('#submit_approve_access'))
.then(el => el.moveTo())
.then(() => client.$('#submit_approve_access content'))
.then(el => el.waitForDisplayed(3000))
.then(() => client.$('#submit_approve_access content'))
.then(el => el.click())
.then(() => client.$('textarea'))
.then(el => el.waitForDisplayed(4000).then(() => el.getValue()))
};
module.exports = authorizeSelenium;
const importer = require('./importer');
/**
* Authorizes Selenium using Google login.
*
* @param {string} authUrl - Authorization URL.
* @param {object} client - Selenium client.
* @returns {Promise<string>} - Value of the textarea element.
*/
async function authorizeSelenium(client, authUrl, loginGoogleFunc = importer.import('log in google')) {
// Navigate to the authorization URL
await client.url(authUrl);
// Login to Google
await loginGoogleFunc(client);
// Wait for the submit button to be displayed
const submitButton = await client.$('#submit_approve_access');
await submitButton.waitForDisplayed(3000);
// Move to the submit button and click it
await submitButton.moveTo().click();
// Wait for the textarea to be displayed
const textarea = await client.$('textarea');
await textarea.waitForDisplayed(4000);
// Return the value of the textarea
return await textarea.getValue();
}
module.exports = authorizeSelenium;
var loginGoogle = importer.import('log in google');
loginGoogle
from another module using the importer
module.function authorizeSelenium(authUrl) {
return client
// Navigate to the provided auth URL
.url(authUrl)
// Perform the login operation using the imported function
.then(() => loginGoogle(client))
// Retrieve the HTML element with id'submit_approve_access'
.then(() => client.$('#submit_approve_access'))
// Wait for the element to be displayed for 3 seconds
.then(el => el.waitForDisplayed(3000))
// Retrieve the'submit_approve_access' element again
.then(() => client.$('#submit_approve_access'))
// Move the cursor to the element
.then(el => el.moveTo())
// Retrieve the'submit_approve_access content' element
.then(() => client.$('#submit_approve_access content'))
// Wait for the element to be displayed for 3 seconds
.then(el => el.waitForDisplayed(3000))
// Retrieve the'submit_approve_access content' element again
.then(() => client.$('#submit_approve_access content'))
// Click the element
.then(el => el.click())
// Retrieve the HTML textarea element
.then(() => client.$('textarea'))
// Wait for the element to be displayed for 4 seconds and return its value
.then(el => el.waitForDisplayed(4000).then(() => el.getValue()))
}
authUrl
parameter and uses the client
object to perform a series of operations.loginGoogle
function.module.exports = authorizeSelenium;
authorizeSelenium
function so it can be used in other modules.