CrossBrowserTesting Support

Support

  • Product
    • Live Testing
    • Automated Testing
    • Record & Replay
    • Visual Testing
  • API Docs
  • Blog
  • Live Q&A
  • Start Testing
CrossBrowserTesting Support » Selenium Testing » Jenkins

Jenkins

Getting Started With Jenkins and CrossBrowserTesting

For this document, we provide example tests located in our Jenkins plugin Github Repository.

Jenkins is a continuous integration tool that lets you automate your development process quickly, safely, and at scale. In this guide we will use Jenkins along with our Jenkins Plugin for testing using the Selenium Webdriver and the Python programming language.

Setting Up Jenkins

  1. Ensure Java is installed on your machine. If you do not have Java installed, we recommend following the documentation: https://www.java.com/en/download/help/download_options.xml
  2. We will be using the Web Application Archive (WAR) file version of Jenkins. This version of Jenkins can be installed on any OS or platform that supports Java.
  3. After downloading the WAR file, run the following command from the terminal/command prompt:
    java -jar jenkins.war
  4. Navigate to http://localhost:8080 and finish set up by waiting for the unlocking  Jenkins and choosing a customization option.

Congratulations! You have successfully setup Jenkins. Now you are ready to install our Jenkins plugin.

Installing Our Jenkins Plugin

via the interface
  1. From the Manage Jenkins page, click Manage Plugins.

  2. Click the Available tab.
  3. Find the CrossBrowserTesting.com Plugin and select the checkbox.
  4. then click either Install without restart or Download now and install after restart.

by hand(not recommended)
  1. Download CrossBrowserTesting.hpi.
  2. Save the downloaded .hpi file into your `$JENKINS_HOME/plugins` directory.
  3. Restart Jenkins.

For more detailed information about our Jenkins Plugin, please visit https://help.crossbrowsertesting.com/integrations/tutorials/installing-jenkins/

Running A Test

You’ll need to use your Username and Authkey to run your tests on CrossBrowserTesting. To get yours, sign up for a free trial or purchase a plan.
  1. Start a new project by clicking New Item -> Freestyle Project and giving your project a name.
  2. From the Build Environment tab, select Crossbrowstesting.com

  3. Since this example demonstrates a Selenium test, Add a Selenium Test should be selected and configured.
    • Select a browser and click Enable Test Results Pages

    • Add CBT Credentials

  4. From the Build tab, select Execute shell (Mac) or Execute Windows batch command (Windows) from the Add build step drop down and add the following command:
    python /PATH_TO_FILE/jenkins_python.py

  5. In a directory of your choice, create file jenkins_python.py with the following content:
    import unittest
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import requests
    import os class SeleniumCBT(unittest.TestCase): def setUp(self): self.username = os.environ['CBT_USERNAME'] self.authkey = os.environ['CBT_APIKEY'] self.api_session = requests.Session() self.api_session.auth = (self.username,self.authkey) self.test_result = None caps = {} caps['name'] = os.environ['CBT_BUILD_NAME'] caps['build'] = os.environ['CBT_BUILD_NUMBER'] caps['browser_api_name'] = os.environ['CBT_BROWSER'] caps['os_api_name'] = os.environ['CBT_OPERATING_SYSTEM'] caps['screen_resolution'] = os.environ['CBT_RESOLUTION'] caps['record_video'] = 'true' try: self.driver = webdriver.Remote( desired_capabilities=caps, command_executor="http://%s:%s@hub.crossbrowsertesting.com:80/wd/hub"%(self.username, self.authkey)) except Exception as e: raise e def test_CBT(self): try: self.driver.implicitly_wait(10) self.driver.get('https://google.com') self.assertEqual(self.driver.title, 'Google') self.test_result = 'pass' except AssertionError as e: # log the error message, and set the score self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots/' + snapshot_hash, data={'description':"AssertionError: " + str(e)}) self.test_result = 'fail' raise self.driver.quit() # Here we make the api call to set the test's score # Pass if it passes, fail if an assertion fails, unset if the test didn't finish if self.test_result is not None: self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id, data={'action':'set_score', 'score':self.test_result}) if __name__ == '__main__': unittest.main()
  6. Save your configurations and run your test by selecting Build Now. Results can be viewed by clicking the build number.

Using the Pipeline

  1. Start a new project by clicking New Item -> Pipeline and giving your project a name. 
  2. From the Pipeline tab, add the following pipeline script:
    
    pipeline{
    
    	agent any
    	stages{
    	stage('build'){
    	steps{
    cbt(credentialsId: 'YOUR_CREDENTIALS_ID', useLocalTunnel: true, tunnelName: "tunnel", localTunnelPath: "", useTestResults: true) {
    cbtSeleniumTest(browser: 'FF64', operatingSystem: 'Mac10.14', resolution: '1366x768') {
     sh 'python /PATH_TO_FILE/jenkins_python.py'
        		}
    		}
    	}
    
    	}
    }
    

    Your credentials ID can be found in the ID section on the Credentials page by selecting Credentials from the Jenkins dropdown menu.

  3. Save your configuration and run your test by selecting Build Now.

Using a Local Connection 

If you would like to test behind your firewall or access non-public sites, you can use our local connection tool directly through our Jenkins plugin. Simply check Use Local Tunnel checkbox. (The CBT NodeJS Tunnel must be installed globally.)

Conclusions

By following the steps outlined in this guide, you are now able to seamlessly integrate Jenkins and CrossBrowserTesting. If you have any questions or concerns, please feel free to reach out to our support team.

Related

Selenium Starting Guides

  • Python
  • Java
  • JavaScript
  • PHP
  • Ruby
  • C#
  • Selenium 101

More Help

  • Parallel Testing
  • Jenkins Integration
  • TeamCity Integration
  • Automation Capabilities
  • Local Testing

See Our GitHub Examples


 



Think you need a human?

Our customer success team will be glad to help you with your question.

Contact Support

Still need a free trial?

Try CrossBrowserTesting free for 7 days and see how we make testing easier.

Start Today

Want the latest tips?

Enter your email and we’ll send you tutorials and browser testing strategies right to your inbox.


Product

  • Live Testing
  • Automated Testing
  • Visual Testing
  • Local Testing
  • Integrations

Resources

  • Browsers & Devices
  • Blog
  • Webinars
  • Security
  • ROI Calculator

Support

  • Help Center
  • CBT Community
  • API Docs
  • Automation Docs
  • Schedule A Demo
  • Enterprise Request

Company

    • About Us
    • Contact Us
    • Careers
    • Terms of Use
    • 1-888-927-6973

© 2019 CrossBrowserTesting.com, LLC. All rights reserved.