Selenium | utilities | you earned it | Search

webdriver

selenium client

This Node.js script uses Selenium WebDriver to create a Chrome browser session, setting environment variables and defining Chrome profile paths based on the operating system. The getClient function creates a new Chrome browser session by setting Chrome profile paths, adding arguments, and returning a promise with the created client instance.

selenium session

The code is designed to manage sessions by reading and writing data to a sessions.json file, utilizing environment variables and file system modules. It exports two functions, readSessions and updateOrAddSession, which handle reading and updating the sessions array, respectively.

webdriver test

The code defines an asynchronous function testDriver that imports a getClient module, sets up a web driver, navigates to Facebook, waits for 4 seconds, and then closes the driver. The function is exported as a module.

close all windows

The code imports necessary classes and functions from the selenium-webdriver module and defines a function closeAllWindows that closes all browser windows except the one specified by the keep argument. The function creates a new instance of WebDriver, gets an array of window handles, and iterates over them to close all windows except the one specified by keep.

selenium executor

The code defines a set of commands for interacting with a web browser using Selenium WebDriver, including launching apps, setting network conditions, and sending DevTools commands. The commands are configured using the configureExecutor function, which takes an executor instance and a vendor prefix as arguments to customize the command URLs for specific vendors.

list sessions

The code imports necessary modules for interacting with web browsers and defines constants and functions for managing Selenium sessions, including verifying individual sessions and retrieving active sessions. The getSessions function is exported as a module export, which can be used to retrieve and verify available Selenium sessions.

selenium select

The code imports three functions (selectDom, evaluateDom, and walkTree) from separate modules and uses them in an asynchronous function called getAllXPath to execute a script on a web page. The getAllXPath function takes three parameters and returns the result of calling the selectDom function after making the evaluateDom and walkTree functions available on the web page.

selenium query

The getAllQuery function is defined as an asynchronous function that executes a script in a browser context using the driver.executeScript method, which involves importing and utilizing external functions for querying and evaluating the DOM. The function takes three parameters - driver, select, and an optional ctx object - and returns the result of executing the queryDom function.

Cell 8

The code requires two modules: ../Core and webdriverio, and imports specific functions and constants from ../Core. It defines a function createWebdriverClient that creates a WebdriverIO client configuration object with various settings and capabilities, including browser name, Chrome-specific options, and log level.

Cell 9

The connectSession function connects a client to a session by managing existing sessions, creating a new one if necessary, and configuring the client's connection retry timeout. It returns the client's session ID if successful, or throws an error if an issue occurs.

Cell 10

This code defines a module that reads session data from a JSON file at SESSIONS_PATH and returns an array of session data. It also includes error handling to reset the session array if an error occurs while reading the file.

Cell 11

This Node.js module manages lock files and session data, providing functions to lock/unlock files and update or add sessions to a JSON file. The module uses the lockfile, fs, and path modules, as well as a custom ../Core module, to perform its operations.

Cell 12

The getSessions function retrieves available sessions for a given client, filtering out inactive sessions based on the lastActive timestamp. It uses a multi-step process to verify sessions, including loading sessions, filtering, mapping, running promises, and deduplicating results.

Cell 13

This code imports necessary modules, sets variables, and defines two primary functions: addPlugins and verifySession. The addPlugins function attaches event listeners to a client object and locks/unlocks promises to update or add session data, while the verifySession function verifies a session by setting the session ID, adding plugins, and interacting with the client object's promise chain.

Cell 14

This code checks if two variables, client and $, are defined, and if so, it creates a new Webdriver client instance and sends the result to the $ function. The code also catches any errors that occur during client creation and sends them to the $ function for handling.

Cell 15

The code checks if client and $ are defined, and if so, executes a block of code. It also contains functions to execute an asynchronous method and handle client window handles, including sending results or errors through the $ object.

Cell 16

This JavaScript code checks if a client object exists and, if so, closes all connections to it by calling the endAll() method. If the client object does not exist, the code does nothing.

Cell 17