The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note

Editing the Host file of the virtual machine will not work if Sauce Connect Proxy is in use. If you are using Sauce Connect Proxy, the Host file of the machine running Sauce Connect Proxy will be referenced and you can make the desired changes there.

 


An example of configuring a Sauce Labs virtual machine with a pre-run executable is editing the host file in the virtual machine, so when the driver tries to access a particular domain, like google.com, it will be redirected to a new IP address, for example 162.222.75.243 (saucelabs.com). As with other prerun configurations, the basic steps are:

...

Having created and uploaded your host file script, you now need to refer to it using the prerun capability in your test script, as shown in this Python example.

Code Block
languagepy
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import unittest
import
time
from selenium import webdriver

class Selenium2OnSauce(unittest.TestCase):

   
def
setUp(self):
        self.desired_capabilities = webdriver.DesiredCapabilities.CHROME
 
      self.desired_capabilities['version'] = '34latest'
        self.desired_capabilities['platform'] = 'OS XmacOS 10.9'
        self.14'
desired_capabilities['name'] = 'Editing the DNS'
       
self.desired_capabilities['prerun'] = {'executable':'https://raw.githubusercontent.com/albedithdiaz/sauceSupport/master/preRunScripts/EditHostFile.sh', 'background': False }



     
        self.driver = webdriver.Remote(command_executorremote_url = 'http://SAUCE_USERNAME:SAUCE_ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub'


driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = self.desired_capabilities)
       
self.driver.implicitly_wait(30)    

    def test_sauce(self):    

   self.driver.get('http://www.googlesaucedemo.com')
       
title = self.driver.title
        self.assertEquals("Cross Browser Testing, Selenium Testing, and Mobile Testing | Sauceassert "Swag Labs", in title)  

    def tearDown(self): 

          self.driver.quit()

if
__name__
==
'__main__':
    unittest.main()