{ "cells": [ { "cell_type": "markdown", "id": "2fb45dc8-5690-4499-be73-0f8998677db3", "metadata": {}, "source": [ "# Managing resources" ] }, { "cell_type": "markdown", "id": "10bf4104-d2a3-4b2a-af8c-1921c99fa6c9", "metadata": {}, "source": [ "Controlling a web browser with Selenium requires several components:\n", "\n", "- a browser installed on the machine you are working on. This is the application that controlled by Selenium.\n", "- a driver that makes the links between the installed application and your code. The driver allows Selenium to control the browser with commands you provide.\n", "\n", "A good management on these components is essential to ensure the stability of your application. It can be easy to handle all of that in a dev environment but managing your resources in production can be trickier.\n", "\n", "`manen` provides several functions and classes whose purpose is to provide simple interfaces to manage browsers and drivers." ] }, { "cell_type": "markdown", "id": "4b361669-f3c7-411a-91c4-606db22ea78b", "metadata": {}, "source": [ "## An API around your browsers and drivers\n", "\n", "Each browser has its own sub-package (defined in `manen.resource`), each one of them providing at least two classes:\n", "\n", "- `application`, implementing some methods in order to get the status of the installed browser.\n", "- `driver` which is a class used as interface with the driver resources, enabling to list and download any drivers available online.\n", "\n", "For now, only two browsers are fully supported by `manen`: Google Chrome and Brave.\n", "The support for other browsers such as Firefox is planned in the coming release.\n", "\n", "In the following example, we will work with Chrome." ] }, { "cell_type": "code", "execution_count": 1, "id": "a1de2a32-12e2-4263-ad55-c01ad1acc507", "metadata": {}, "outputs": [], "source": [ "from manen.resource import chrome" ] }, { "cell_type": "markdown", "id": "80976e3c-1234-407a-af71-d87fa2260521", "metadata": {}, "source": [ "Thanks to the `application` class, we can check that the browser is correctly installed and retrieve the current version." ] }, { "cell_type": "code", "execution_count": 2, "id": "d3c6876d-fff1-4560-9fd4-04d3582c55f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(98, 0, 4758, 102)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "assert chrome.application.is_installed()\n", "chrome_version = chrome.application.installed_version()\n", "chrome_version" ] }, { "cell_type": "markdown", "id": "7571f92b-ee29-45a1-bac0-8aae6d1091f8", "metadata": {}, "source": [ "`manen` also provides the same interface for the browser Brave." ] }, { "cell_type": "code", "execution_count": 3, "id": "88128f4f-9c56-4984-84e6-08293cfece1a", "metadata": {}, "outputs": [], "source": [ "from manen.resource import brave" ] }, { "cell_type": "code", "execution_count": 4, "id": "f312d5fe-e983-4600-a94d-3135e5121e24", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(98, 1, 35, 101)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "assert brave.application.is_installed()\n", "brave_version = brave.application.installed_version()\n", "brave_version" ] }, { "cell_type": "markdown", "id": "882eb00e-f4e9-4bf6-ad7b-e7f1ba024c37", "metadata": {}, "source": [ "
manen
will have slightly the same interface, and can be imported using the same path `manen.resource.{browser_name}`.\n",
"