Created
September 10, 2018 04:46
-
-
Save ckzgraphics/615788e04cd8f07e4577585d4f76d789 to your computer and use it in GitHub Desktop.
Add Chrome Extension (Download the CRX file first and provide the path to it)
This file contains 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 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 ChromeExtension_PlugIn_Test { | |
public static void main(String[] args) { | |
String USERNAME = "<BROWSERSTACK_USERNAME>"; | |
String AUTOMATE_KEY = "<BROWSERSTACK_ACCESS_KEY>"; | |
String HUB_URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"; | |
String AUT_URL = "https://www.whatsmybrowser.org/"; | |
WebDriver webDriver = null; | |
ChromeOptions options = null; | |
URL URLObj = null; | |
DesiredCapabilities caps = null; | |
try { | |
URLObj = new URL(HUB_URL); | |
options = new ChromeOptions(); | |
options.addExtensions(new File("/Users/test/Downloads/Page Ruler.crx")); // DOWNLOAD THE CRX FILE | |
caps = new DesiredCapabilities(); | |
caps.setCapability(ChromeOptions.CAPABILITY, options); | |
caps.setCapability("browser", "Chrome"); | |
caps.setCapability("browser_version", "65.0"); | |
caps.setCapability("os", "Windows"); | |
caps.setCapability("os_version", "10"); | |
caps.setCapability("project", "Test Run"); | |
caps.setCapability("build", "Support Automate"); | |
caps.setCapability("name", "Test: Add Chrome Extension/PlugIn"); | |
caps.setCapability("acceptSslCerts", "true"); | |
caps.setCapability("browserstack.debug", "true"); | |
caps.setCapability("browserstack.console", "verbose"); | |
caps.setCapability("browserstack.selenium_version", "3.11.0"); | |
webDriver = new RemoteWebDriver(URLObj, caps); | |
webDriver.manage().window().maximize(); | |
webDriver.get(AUT_URL); | |
Thread.sleep(10000); | |
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); | |
// File DestFile=new File("/Users/test.png"); | |
// FileUtils.copyFile(SrcFile, DestFile); | |
} 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