BrowserStack has a Visual Logs feature to take screenshots automatically during your Selenium test without you initiating a screenshot explicitly through test code.
Taking screenshots using the Visual Logs capability is currently not supported on BrowserStack’s macOS Snow Leopard and Lion computers.
These contain the screenshots that are auto-generated during each Selenium command that your code executes. Visual logs help with debugging the exact step and how the page was rendered when the failure occurred. They also help identify any layout or design related issues with your web pages on different browsers.
Visual logs are disabled by default. You can enable them by using the debug capability.
You can use either Selenium 4 or Selenium Legacy JSON to organize your tests.
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
You can choose to take a screenshot from your test script and either save it to your local machine or only display it in session’s text logs:
Take screenshot and download it to your local machine
You can choose when to take a screenshot from your test script and also save these screenshots to the machine that runs the automated tests. If you are on a CI/CD setup, make sure you transfer these screenshots before you wind down the machine.
Here is how you take a screenshot and save it to your machine:
// Import the relevant packages// ... your test code// Take a screenshot and save it to /location/to/screenshot.png
driver =(RemoteWebDriver)newAugmenter().augment(driver);File srcFile =(File)((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);FileHandler.copy(srcFile,newFile("/location/to/screenshot.png"));// ... your test code
var fs =require('fs');
webdriver.WebDriver.prototype.saveScreenshot=function(filename){return driver.takeScreenshot().then(function(data){
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''),'base64',function(err){if(err)throw err;});})};
driver.saveScreenshot('snapshot1.png')
<?phprequire_once('vendor/autoload.php');useFacebook\WebDriver\Remote\RemoteWebDriver;useFacebook\WebDriver\WebDriverBy;$caps=array("browser"=>"Chrome","browser_version"=>"88.0","realMobile"=>"true","os"=>"Windows","os_version"=>"10","name"=>"BStack-[Php] Sample Test",// test name"build"=>"BStack Build Number 1"// CI/CD job or build name);$web_driver=RemoteWebDriver::create("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps);# Searching for 'BrowserStack' on google.com$web_driver->get("https://google.com");file_put_contents('screenshot.png',$web_driver->takeScreenshot());$web_driver->quit();?>
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
desired_cap ={'browser':'Chrome','browser_version':'88.0','os':'Windows','os_version':'10','name':'BStack-[Python] Sample Test',# test name'build':'BStack Build Number 1'# CI/CD job or build name}
options.set_capability('bstack:options', desired_cap)
driver = webdriver.Remote(
command_executor='https://hub-cloud.browserstack.com/wd/hub',
options=options)
driver.get("https://www.google.com")
driver.save_screenshot('screenshots.png')
driver.quit()
require'rubygems'require'selenium-webdriver'# Input capabilities
caps =Selenium::WebDriver::Remote::Capabilities.new
caps['os']='Windows'
caps['os_version']='10'
caps['browser']='Chrome'
caps['browser_version']='88.0'
caps['name']='BStack-[Ruby] Sample Test'# test name
caps['build']='BStack Build Number 1'# CI/CD job or build name
driver =Selenium::WebDriver.for(:remote,:url=>"https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",:desired_capabilities=> caps)# Searching for 'BrowserStack' on google.com
driver.navigate.to "https://www.google.com"
driver.save_screenshot("screenshots.png")
driver.quit
Did this page help you?
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked