Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Created September 12, 2019 09:47
Show Gist options
  • Save ckzgraphics/d4b01dfd8be5839fa45839b91ec25a1c to your computer and use it in GitHub Desktop.
Save ckzgraphics/d4b01dfd8be5839fa45839b91ec25a1c to your computer and use it in GitHub Desktop.
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ChangeBrowserLocale_Chrome {
public static void main(String[] args) {
// CHECK YOUR BROWSERSTACK CREDS HERE- https://www.browserstack.com/accounts/settings
String USERNAME = "<BROWSERSTACK_USERNAME>";
String AUTOMATE_KEY = "<BROWSERSTACK_ACCESS_KEY>";
String HUB_URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
WebDriver webDriver = null;
ChromeOptions options = null;
String AUT_URL = "http://www.facebook.com";
URL URLObj = null;
DesiredCapabilities caps = null;
try {
URLObj = new URL(HUB_URL);
options = new ChromeOptions();
// CHECK LOCALE CODE HERE- https://stackoverflow.com/questions/3191664/list-of-all-locales-and-their-short-codes
options.addArguments("--lang=zh_CN");
// CHECK THE SUPPORTED CAPS HERE- https://www.browserstack.com/automate/capabilities
caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps.setCapability("project", "Build v1");
caps.setCapability("build", "Test Run");
caps.setCapability("name", "Test: Change Browser Locale");
caps.setCapability("browserstack.captureCrash", "true");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "7");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "73");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.console", "verbose");
webDriver = new RemoteWebDriver(URLObj, caps);
webDriver.get(AUT_URL);
System.out.println("TITLE :: " + webDriver.getTitle());
take_screenshot(webDriver);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(webDriver != null){
webDriver.quit();
}
}
} // MAIN END
public static void take_screenshot(WebDriver webDriver){
try {
TakesScreenshot scrShot =((TakesScreenshot)webDriver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
} catch (Exception e) {
e.printStackTrace();
}
} // FUNC END
} // CLASS END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment