How to use create_firefox_profile method in pytest-mozwebqa

Best Python code snippet using pytest-mozwebqa_python

selenium_client.py

Source:selenium_client.py Github

copy

Full Screen

...76 capabilities = self.create_chrome_options(77 self.chrome_options,78 self.extension_paths).to_capabilities()79 if self.browser_name.upper() == 'FIREFOX':80 profile = self.create_firefox_profile(81 self.firefox_preferences,82 self.profile_path,83 self.extension_paths)84 if self.browser_version:85 capabilities['version'] = self.browser_version86 capabilities['platform'] = self.platform.upper()87 executor = 'http://%s:%s/wd/hub' % (self.host, self.port)88 try:89 self.selenium = webdriver.Remote(command_executor=executor,90 desired_capabilities=capabilities or None,91 browser_profile=profile)92 except AttributeError:93 valid_browsers = [attr for attr in dir(webdriver.DesiredCapabilities) if not attr.startswith('__')]94 raise AttributeError("Invalid browser name: '%s'. Valid options are: %s" % (self.browser_name, ', '.join(valid_browsers)))95 elif self.driver.upper() == 'CHROME':96 options = None97 if self.chrome_options or self.extension_paths:98 options = self.create_chrome_options(99 self.chrome_options,100 self.extension_paths)101 if self.chrome_path:102 self.selenium = webdriver.Chrome(executable_path=self.chrome_path,103 chrome_options=options,104 desired_capabilities=capabilities or None)105 else:106 self.selenium = webdriver.Chrome(chrome_options=options,107 desired_capabilities=capabilities or None)108 elif self.driver.upper() == 'FIREFOX':109 binary = self.firefox_path and FirefoxBinary(self.firefox_path) or None110 profile = self.create_firefox_profile(111 self.firefox_preferences,112 self.profile_path,113 self.extension_paths)114 self.selenium = webdriver.Firefox(115 firefox_binary=binary,116 firefox_profile=profile,117 capabilities=capabilities or None)118 elif self.driver.upper() == 'IE':119 self.selenium = webdriver.Ie()120 elif self.driver.upper() == 'PHANTOMJS':121 self.selenium = webdriver.PhantomJS()122 elif self.driver.upper() == 'OPERA':123 capabilities.update(webdriver.DesiredCapabilities.OPERA)124 self.selenium = webdriver.Opera(executable_path=self.opera_path,125 desired_capabilities=capabilities)126 elif self.driver.upper() == 'BROWSERSTACK':127 from cloud import BrowserStack128 self.cloud = BrowserStack()129 self.selenium = self.cloud.driver(130 self.test_id, capabilities, self.options)131 elif self.driver.upper() == 'SAUCELABS':132 from cloud import SauceLabs133 self.cloud = SauceLabs()134 self.selenium = self.cloud.driver(135 self.test_id, capabilities, self.options, self.keywords)136 else:137 self.selenium = getattr(webdriver, self.driver)()138 if self.event_listener is not None and not isinstance(self.selenium, EventFiringWebDriver):139 self.selenium = EventFiringWebDriver(self.selenium, self.event_listener())140 @property141 def session_id(self):142 return self.selenium.session_id143 def create_firefox_profile(self, preferences, profile_path, extensions):144 profile = webdriver.FirefoxProfile(profile_path)145 for p in preferences:146 name, value = p.split(':')147 # handle integer preferences148 if value.isdigit():149 value = int(value)150 # handle boolean preferences151 elif value.lower() in ['true', 'false']:152 value = value.lower() == 'true'153 profile.set_preference(name, value)154 profile.assume_untrusted_cert_issuer = self.assume_untrusted155 profile.update_preferences()156 for extension in extensions:157 profile.add_extension(extension)...

Full Screen

Full Screen

sap_profiles.py

Source:sap_profiles.py Github

copy

Full Screen

...10from selenium import webdriver11DEFAULT_PROFILE = os.path.join("~", ".pysapwebprofile")12CA_URL = "https://ca.mit.edu/"13EXTENSION_URL = "https://addons.mozilla.org/en-us/firefox/addon/startupmaster/"14def create_firefox_profile(profile_dir=DEFAULT_PROFILE, overwrite=False):15 """16 Guide the user through setting up a Firefox profile for use with pysapweb.17 This involves two steps: installing an MIT certificate, and installing an18 extension to prompt for the Firefox Master Password on startup. (The19 extension is necessary because if Firefox prompts for this password during20 a page load, Selenium will lose its handle on the page.)21 """22 profile_dir = os.path.expanduser(profile_dir)23 if os.path.exists(profile_dir):24 if overwrite:25 shutil.rmtree(profile_dir)26 else:27 raise OSError("Profile directory %s already exists." % profile_dir)28 profile = webdriver.FirefoxProfile()29 profile.accept_untrusted_certs = False30 profile.set_preference("security.default_personal_cert",31 "Select Automatically")32 profile.set_preference("datareporting.healthreport.uploadEnabled",33 False)34 profile.set_preference("places.history.enabled",35 False)36 print ""37 print " 1. Please load a certificate into the browser and set"38 print " a master password."39 print ""40 sys.stdout.write(" - Starting Firefox...")41 browser = webdriver.Firefox(profile)42 browser.get(CA_URL)43 print "Done"44 raw_input(" - To continue, press ENTER.")45 print ""46 print " 2. Please accept installation of the extension, but"47 print " do not restart."48 print ""49 browser.get(EXTENSION_URL)50 browser.find_element_by_css_selector(".prominent.installer").click()51 raw_input(" - To continue, press ENTER.")52 # don't use browser.quit() b/c removes profile dir53 browser.binary.kill()54 temp_dir = browser.firefox_profile.path55 shutil.move(temp_dir, profile_dir)56 # delete extension to avoid future errors57 shutil.rmtree(os.path.join(profile_dir, "extensions",58 "fxdriver@googlecode.com"))59 print " - Profile created successfully!"60def load_firefox(profile_dir=DEFAULT_PROFILE):61 """Return a WebDriver instance with the given Firefox profile loaded."""62 profile_dir = os.path.expanduser(profile_dir)63 profile = webdriver.FirefoxProfile(profile_dir)64 browser = webdriver.Firefox(profile)65 return browser66if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-mozwebqa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful