selenium - How to run one python webdriver test in multiple browsers -


i testing out browserstack , have small suite of selenium webdriver tests written in python. goal run tests in several different browsers. using desired_capabilities specify browser, version, os, etc.

what way repeat test different browser without having bunch of different py files?

here's how tests setup:

from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.common.keys import keys selenium.webdriver.support.ui import select selenium.common.exceptions import nosuchelementexception selenium.webdriver.common.desired_capabilities import desiredcapabilities import unittest, time, re   desired_cap = {'browser': 'chrome', 'browser_version': '33.0', 'os': 'os x', 'os_version': 'mavericks', 'resolution': '1600x1200'} desired_cap['browserstack.debug'] = true  class regwd(unittest.testcase):     def setup(self):         self.driver = webdriver.remote(         command_executor='http://browserstackstuff.com',         desired_capabilities=desired_cap)         self.base_url = "http://blahtestsite.com/" 

you try this:

from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.common.keys import keys selenium.webdriver.support.ui import select selenium.common.exceptions import nosuchelementexception selenium.webdriver.common.desired_capabilities import desiredcapabilities import unittest, time, re   desired_cap = [] desired_cap.append({'browser': 'chrome', 'browser_version': '33.0', 'os': 'os x', 'os_version': 'mavericks', 'resolution': '1600x1200'}) desired_cap.append({'browser': 'firefox', 'browser_version': '27.0', 'os': 'os x', 'os_version': 'mavericks', 'resolution': '1600x1200'})  class regwd(unittest.testcase):     def setup(self):         driver_instance in desired_cap:             driver_instance['browserstack.debug'] = true             self.driver = webdriver.remote(             command_executor='http://browserstackstuff.com',             desired_capabilities=driver_instance)             self.base_url = "http://blahtestsite.com/" 

just make desired_cap tuple, , append in browser versions want it. add loop cycles through each browser instance. had move

desired_cap['browserstack.debug'] = true 

from outside of class, following inside of class

driver_instance['browserstack.debug'] = true 

because brackets make weird. needs integer between [] call specific instance. rather making loop outside of class set each instance true, moved line class runs each instance of browser.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -