Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Created December 11, 2018 05:04
Show Gist options
  • Select an option

  • Save ckzgraphics/418cf54ed3a60f057fcc0834e9bef010 to your computer and use it in GitHub Desktop.

Select an option

Save ckzgraphics/418cf54ed3a60f057fcc0834e9bef010 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Point;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.bs.global.GlobalVariable;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
public class CHROME_71_REACT_ISSUE {
public static void main(String[] args) {
System.out.println("Executing :: CHROME_71_REACT_ISSUE");
String USERNAME = "<USERNAME>";
String AUTOMATE_KEY = "<ACCESS_KEY>";
String HUB_URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
JavascriptExecutor js = null;
WebDriver webDriver = null;
ChromeOptions options = null;
FirefoxProfile firefoxProfile = null;
Map<String, Object> prefs = null;
Keys keys = null;
WebElement ele = null;
WebDriverWait wait = null;
Actions act = null;
String AUT_URL = null;
AUT_URL = "https://the-internet.herokuapp.com/login"; // ON THIS THE CLEAR COMMAND WORKS
AUT_URL = "https://foxhound87.github.io/mobx-react-form-demo/demo";
URL URLObj = null;
DesiredCapabilities caps = null;
try {
URLObj = new URL(HUB_URL);
caps = new DesiredCapabilities();
caps.setCapability("browserName", "Chrome");
caps.setCapability("browserVersion", "71.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browserstack.use_w3c", "true");
caps.setCapability("project", "Test Run");
caps.setCapability("build", "Support Automate");
caps.setCapability("name", "Test: Chrome Options [Incognito]");
caps.setCapability("browserstack.captureCrash", "true");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.console", "verbose");
webDriver = new RemoteWebDriver(URLObj, caps);
wait = new WebDriverWait(webDriver, 10000);
act = new Actions(webDriver);
js = (JavascriptExecutor)webDriver;
webDriver.get(AUT_URL);
Thread.sleep(4000);
System.out.println("TITLE :: " + webDriver.getTitle());
Capabilities cap = ((RemoteWebDriver) webDriver).getCapabilities();
String browserName = cap.getBrowserName().toLowerCase();
System.out.println("browserName :: " + browserName);
String os = cap.getPlatform().toString();
System.out.println("os :: " + os);
String v = cap.getVersion().toString();
System.out.println("version :: " + v);
Thread.sleep(5000);
ele = webDriver.findElement(By.xpath(".//input[@name='username']"));
Thread.sleep(2000);
ele.clear();
Thread.sleep(2000);
ele.sendKeys("KOOKOK");
Thread.sleep(2000);
take_screenshot(webDriver);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(webDriver != null){
webDriver.quit();
}
}
}
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment