#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import unittest
from xvfbwrapper import Xvfb
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


class Test(unittest.TestCase):

    def setUp(self):
        self.xvfb = os.environ.get("ENABLE_XVFB", False)
        if self.xvfb:
            self.vdisplay = Xvfb(width=1280, height=720)
            self.vdisplay.start()

    def tearDown(self):
        if self.driver:
            self.driver.quit()
        if self.xvfb and self.vdisplay:
            self.vdisplay.stop()

    def test_ff(self):
        self.driver = webdriver.Firefox()
        self.driver.get("https://www.wikipedia.org")
        self.assertIn("Wikipedia", self.driver.title)

    def test_chrome(self):
        opts = Options()
        if "TRAVIS" in os.environ:  # github.com/travis-ci/travis-ci/issues/938
            opts.add_argument("--no-sandbox")
        # Fix for https://code.google.com/p/chromedriver/issues/detail?id=799
        opts.add_experimental_option("excludeSwitches",
                                     ["ignore-certificate-errors"])
        self.driver = webdriver.Chrome(chrome_options=opts)
        self.driver.get("https://www.wikipedia.org")
        self.assertIn("Wikipedia", self.driver.title)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()

@@ -292,16 +292,75 @@
  False)%0A
+        self.browser = os.environ.get(%22BROWSER%22, %22Chrome%22)%0A
         
@@ -463,16 +463,202 @@
 .start()
+%0A        if self.browser == %22Firefox%22:%0A            self.driver = self.get_ff_driver()%0A        else:%0A            self.driver = self.get_chrome_driver()%0A        self.load = self.driver.get
 %0A%0A    de
@@ -816,15 +816,21 @@
 def 
-tes
+ge
 t_ff
+_driver
 (sel
@@ -837,37 +837,30 @@
 f):%0A        
-self.driver =
+return
  webdriver.F
@@ -872,135 +872,34 @@
 x()%0A
+%0A
     
-    self.driver.get(%22https://www.wikipedia.org%22)%0A        self.assertIn(%22Wikipedia%22, self.driver.title)%0A%0A    def test_chrome
+def get_chrome_driver
 (sel
@@ -1263,29 +1263,22 @@
         
-self.driver =
+return
  webdriv
@@ -1307,16 +1307,59 @@
 ns=opts)
+%0A%0A    def test_should_load_wikipedia(self):
 %0A       
@@ -1364,26 +1364,20 @@
    self.
-driver.get
+load
 (%22https:

Read browser type from environment var, refactor.