flexibox

One single end point to get started with your selenium codebase in a go

View the Project on GitHub flu-x/flexibox

Flexibox

Flexibox logo

Flexibox is the a selenium wrapper for all browsers and browser configurations. This module is a single end point to access all the browser drivers and as well as the webdriver object for all the respective browsers along with the installation of your selenium module.

Problem Statement

With the very fast pace of development, it has now become very important to have regular release cycle and with it it should be also kept in mind that we do a quality release. For this reason we have to have our tests automated as well so that we can have a centralised reports for regressions and other flaws in the system at the end of each build.

Now, for a stable build we have to check that our application is compatible with different browsers and platforms. When we start implementing a framework based out of Selenium WebDriver, for the code to get executed in different browsers we have to configure each of the browsers separately and make a call to the browser based on the requirement. Phewww !! That is some good amount of code written.

The Idea

The problem statement that has been defined above was the reason I took out time to ease this entire process of setting up the browser drivers and the respective configurations for each browser. What if this process can be reduced down into few steps of execution? That is how I ended up with the idea and the implementation of Flexibox.

Features covered up by ‘Flexibox’

Flexibox by functionality

functionality screenshot

There are two ways in which you can use Flexibox.

You can refer to the above diagram for reference.

Installing and Updating driver packages

Install Flexibox module

Modules installed with flexibox

Make sure you have ssh configured in GitHub. You can also use https as well to install the module. But preferrable would be if you have ssh configured in GitHub.

To install Flexibox from GitHub using HTTPS run the command:

pip install git+https://github.com/flexibox/Flexibox.git

Update Drivers

Get started with Flexibox

Browser Controller class by functionality

The Browser Controller class provides you with some eccentric methods that can be utilised to achieve the required functions.

Create instance for Chrome

	from flexibox.generic_functions.chrome_object import ChromeDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	from time import sleep

	class Test_1():
		def test_chromedriver_type1(self):
			chromedriver = ChromeDriverObject()
			controller = Browser_controller()
			driver = chromedriver.set_chromedriver_object()
			controller.get_url(driver, "https://www.google.co.in")
			controller.implicit_wait_time(driver, 4)
			current_url = controller.get_current_url(driver)
			print current_url
	from flexibox.generic_functions.chrome_object import ChromeDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	class Test_1():
		def test_chromedriver_type1(self):
			chromedriver = ChromeDriverObject()
			controller = Browser_controller()
			driver = chromedriver.set_chromedriver_object('--headless')
			controller.get_url(driver, "https://www.google.co.in")
			controller.implicit_wait_time(driver, 4)
			current_url = controller.get_current_url(driver)
			print current_url

Create instance for Firefox

	from flexibox.generic_functions.gecko_object import GeckoDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	class Test1():
		def test_geckodriver_type1(self):
			geckodriver = GeckoDriverObject()
			controller = Browser_controller()
			driver = geckodriver.set_geckodriver_object()
			controller.implicit_wait_time(driver, 4)
			controller.get_url(driver, "https://www.google.co.in")
			current_url = controller.get_current_url(driver)
			print current_url
			print driver.title
	from flexibox.generic_functions.gecko_object import GeckoDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	class Test1():
		def test_geckodriver_type1(self):
			geckodriver = GeckoDriverObject()
			controller = Browser_controller()
			driver = geckodriver.set_geckodriver_object('--headless')
			controller.implicit_wait_time(driver, 4)
			controller.get_url(driver, "https://www.google.co.in")
			current_url = controller.get_current_url(driver)
			print current_url
			print driver.title

Create instance for Opera

	from flexibox.generic_functions.opera_object import OperaDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	class Test1():
		def test_operadriver_type1(self):
			operadriver = OperaDriverObject()
			controller = Browser_controller()
			driver = operadriver.set_operadriver_object()
			controller.implicit_wait_time(driver, 4)
			controller.get_url(driver, "https://www.google.co.in")
			current_url = controller.get_current_url(driver)
			print current_url
			print driver.title

Create instance for Safari

	from flexibox.generic_functions.safari_object import SafariDriverObject
	from flexibox.generic_functions.browser_controller import Browser_controller
	class Test_1():
		def test_safaridriver_type1(self):
			safaridriver = SafariDriverObject()
			controller = Browser_controller()
			driver = safaridriver.set_safaridriver_object()
			controller.get_url(driver, "https://www.google.co.in")
			controller.implicit_wait_time(driver, 4)
			current_url = controller.get_current_url(driver)
			print current_url
			print driver.title
			driver.quit()

P.S: Safaridriver comes shipped with the Safari browser by default. You have to enable the Allow Remote Automation option from the Develop menu. Please check this screenshot. Safari

Keep in mind that your safari version has to be more than 10. If it is not 10 or more than 10 then please update your Safari version.

Deleting all browser driver

To delete all browser drivers from /usr/local/bin run the command:

   flexibox delete --driver=all

Running flexibox using grid

Use the docker containers for selenium grid to start the docker services using the following instructions:

For running Docker Hub

$ docker run -p 4444:4444 --name selenium-hub selenium/hub
# Run the hub, forwarding the "4444" port from the docker container to the host machine.

For running the CHROME node

$ docker run --link selenium-hub:hub selenium/node-chrome
# Run the chrome node and link it to the `--name` we specified for the hub.

For running the FIREFOX node

$ docker run --link selenium-hub:hub selenium/node-firefox
# Run the firefox node and link it to the `--name` we specified for the hub.

Running flexibox for chrome node

import unittest

from flexibox.core.browser_controller import BrowserController
from flexibox.generic_functions.remotechrome_object import RemotechromedriverObject


class Test_chromeremote(unittest.TestCase):
    def test_chromedriver_type_remote(self):
        chromedriver = RemotechromedriverObject()
        controller = BrowserController()
        driver = chromedriver.set_remote_chromedriver_object("http://localhost:4444/wd/hub")
        controller.get_url(driver, "https://www.google.co.in")
        controller.implicit_wait_time(driver, 4)
        current_url = controller.get_current_url(driver)
        print(current_url)
        controller.tear_browser(driver)

Running flexibox for firefox node

import unittest

from flexibox.core.browser_controller import BrowserController
from flexibox.generic_functions.remotegecko_object import RemotegeckodriverObject


class Test_firefoxremote(unittest.TestCase):
    def test_firefox_type_remote(self):
        firefoxdriver = RemotegeckodriverObject()
        controller = BrowserController()
        driver = firefoxdriver.set_remote_geckodriver_object("http://localhost:4444/wd/hub")
        controller.get_url(driver, "https://www.google.co.in")
        controller.implicit_wait_time(driver, 4)
        current_url = controller.get_current_url(driver)
        print(current_url)
        controller.tear_browser(driver)

Codacy Badge