Skip to content

Instantly share code, notes, and snippets.

@Jaimin180296
Created February 10, 2021 22:24
Show Gist options
  • Save Jaimin180296/6fef22b09d129c223aacb8e7d002667b to your computer and use it in GitHub Desktop.
Save Jaimin180296/6fef22b09d129c223aacb8e7d002667b to your computer and use it in GitHub Desktop.
Access Public
package Assignment;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class RunBehindProxy {
public static final String USERNAME = <userName>";
public static final String AUTOMATE_KEY = "<accessKey>";
public static final String URL = "http://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "73.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browserstack.networkLogs", "true");
caps.setCapability("browserstack.local", "true");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
// Run as per use case
System.getProperties().put("http.proxyHost", "<HOST>");
System.getProperties().put("http.proxyPort", "<PORT>");
System.getProperties().put("http.proxyUser", "<USER>");
System.getProperties().put("http.proxyPassword", "<PASSWORD>");
System.getProperties().put("https.proxyHost", "<HOST>");
System.getProperties().put("https.proxyPort", "<PORT>");
System.getProperties().put("https.proxyUser", "<USER>");
System.getProperties().put("https.proxyPassword", "<PASSWORD>");
driver.get("https://www.browserstack.com/");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("BrowserStack");
element.submit();
System.out.println(driver.getTitle());
System.out.println(driver.getTitle());
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment