Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Created September 12, 2019 09:47
Show Gist options
  • Save ckzgraphics/03a6b08ca2553c603a6ea4c1a3fe7641 to your computer and use it in GitHub Desktop.
Save ckzgraphics/03a6b08ca2553c603a6ea4c1a3fe7641 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.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ChangeBrowserLocale_Firefox {
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;
FirefoxProfile firefoxProfile = null;
String AUT_URL = "http://www.facebook.com";
URL URLObj = null;
DesiredCapabilities caps = null;
try {
URLObj = new URL(HUB_URL);
firefoxProfile = new FirefoxProfile();
// CHECK LOCALE CODE HERE- https://stackoverflow.com/questions/3191664/list-of-all-locales-and-their-short-codes
firefoxProfile.setPreference("intl.accept_languages", "zh_CN");
// CHECK THE SUPPORTED CAPS HERE- https://www.browserstack.com/automate/capabilities
caps = new DesiredCapabilities();
caps.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
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", "10");
caps.setCapability("browser", "Firefox");
caps.setCapability("browser_version", "62");
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