Created
October 12, 2021 21:13
-
-
Save Jaimin180296/d6df3563ceebb406b21ccf60e2deed0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.io.FileUtils; | |
import org.openqa.selenium.*; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import java.io.File; | |
import java.net.URL; | |
import java.util.ArrayList; | |
public class Sample { | |
public static String userName = ""; | |
public static String accessKey = ""; | |
static ArrayList<String> arlist; | |
public static void main(String[] args) throws Exception { | |
DesiredCapabilities caps = new DesiredCapabilities(); | |
caps.setCapability("os", "Windows"); | |
caps.setCapability("os_version", "10"); | |
caps.setCapability("browser", "Chrome"); | |
caps.setCapability("browser_version", "latest"); | |
WebDriver driver = new RemoteWebDriver(new URL("https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub"), caps); | |
arlist = new ArrayList<String>(); | |
arlist.add("https://www.google.com/"); | |
arlist.add("https://www.browserstack.com/"); | |
for (int i = 0; i < arlist.size(); i++) { | |
driver.get(arlist.get(i)); | |
takeSnapShot(driver, "/Users/jaimin/IdeaProjects/testng-browserstack/src/test/i.png"); | |
} | |
} | |
public static void takeSnapShot(WebDriver webdriver, String fileWithPath) throws Exception { | |
//Convert web driver object to TakeScreenshot | |
TakesScreenshot scrShot = ((TakesScreenshot) webdriver); | |
//Call getScreenshotAs method to create image file | |
File SrcFile = scrShot.getScreenshotAs(OutputType.FILE); | |
//Move image file to new destination | |
File DestFile = new File(fileWithPath); | |
//Copy file at destination | |
FileUtils.copyFile(SrcFile, DestFile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment