One single end point to get started with your selenium codebase in a go
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.
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 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.
There are two ways in which you can use Flexibox.
You can refer to the above diagram for reference.
To install Flexibox using PiP run the command:
pip install flexibox
To install Flexibox from GitHub run the command:
pip install git+git://github.com/flexibox/Flexibox.git
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
To download chromedriver run the command
flexibox download --driver=chromedriver
To download geckodriver run the command
flexibox download --driver=geckodriver
To download operadriver run the command
flexibox download --driver=operadriver
To update chromedriver run the command
flexibox update --driver=chromedriver
To update geckodriver run the command
flexibox update --driver=geckodriver
To update operadriver run the command
flexibox update --driver=operadriver
The Browser Controller
class provides you with some eccentric methods that can be utilised to achieve the required functions.
get_url(driver, url): request the required url entered. Pass the required driver object and the ‘url’ as parameters.
implicit_wait_time(driver, time): Apply implicit wait before the dom loads. Pass the required driver object and the time as parameters.
set_window_size(driver, height, width): Set the window size for the current running browser. Pass the required driver object, height and the width of the window.
get_current_url(driver): Get the current url. Pass the required driver object as parameter.
get_network_requests(driver): Get all the network requests for the current page. Pass the required driver object as parameter.
performance_metrics(driver): Get required page performance data. Pass the required driver object as parameter.
check_console_logs(driver): Get all console logs. Pass the required driver object as parameter.
get_page_source(driver): Get the current page source. Pass the required driver object as parameter.
get_site_cookies(driver): Get all the site cookies. Pass the required driver object as parameter.
ChromeDriverObject
classChromeDriverObject
class to call the set_chromedriver_object
method.Browser_controller
class to use the generic methods. 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
headless
feature you have to pass the argument ‘–headless’ in the set_chromedriver_object()
method 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
GeckoDriverObject
classGeckoDriverObject
class to call the set_geckodriver_object
method.Browser_controller
class to use the generic methods. 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
headless
feature you have to pass the argument ‘–headless’ in the set_geckodriver_object()
method 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
OperaDriverObject
classOperaDriverObject
class to call the set_operadriver_object
methodBrowser_controller
class to use the generic methods. 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
SafariDriverObject
classSafariDriverObject
class to call the set_safaridriver_object
methodBrowser_controller
class to use the generic methods. 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.
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.
To delete all browser drivers from /usr/local/bin
run the command:
flexibox delete --driver=all
Use the docker containers for selenium grid to start the docker services using the following instructions:
$ 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.
$ docker run --link selenium-hub:hub selenium/node-chrome
# Run the chrome node and link it to the `--name` we specified for the hub.
$ docker run --link selenium-hub:hub selenium/node-firefox
# Run the firefox node and link it to the `--name` we specified for the hub.
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)
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)