Created
August 14, 2019 18:18
-
-
Save ckzgraphics/d8daef25873882cbb8e7772eb0943cdc to your computer and use it in GitHub Desktop.
This file contains hidden or 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.By; | |
import org.openqa.selenium.JavascriptExecutor; | |
import org.openqa.selenium.OutputType; | |
import org.openqa.selenium.TakesScreenshot; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
public class DEBUG_Chrome_DefaultContext_Issue { | |
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"; | |
JavascriptExecutor js = null; | |
WebDriver webDriver = null; | |
WebElement ele = null; | |
String AUT_URL = "<TEST_URL>"; | |
URL URLObj = null; | |
DesiredCapabilities caps = null; | |
try { | |
URLObj = new URL(HUB_URL); | |
caps = new DesiredCapabilities(); | |
caps.setCapability("browserName", "Chrome"); | |
caps.setCapability("browserVersion", "69.0"); | |
caps.setCapability("os", "Windows"); | |
caps.setCapability("os_version", "10"); | |
caps.setCapability("project", "Test Run"); | |
caps.setCapability("build", "Debug Pega"); | |
caps.setCapability("name", "Test: Chrome 69"); | |
caps.setCapability("browserstack.console", "verbose"); | |
caps.setCapability("browserstack.debug", "true"); | |
caps.setCapability("browserstack.video", "true"); | |
caps.setCapability("browserstack.local", "true"); | |
webDriver = new RemoteWebDriver(URLObj, caps); | |
js = (JavascriptExecutor)webDriver; | |
webDriver.manage().window().maximize(); | |
webDriver.get(AUT_URL); | |
webDriver.findElement(By.id("email")).sendKeys("<USERNAME>"); | |
Thread.sleep(1000); | |
take_screenshot(webDriver); | |
webDriver.findElement(By.id("password")).sendKeys("<PASSWORD>"); | |
Thread.sleep(1000); | |
take_screenshot(webDriver); | |
webDriver.findElement(By.id("loginButton")).click(); | |
Thread.sleep(3000); | |
take_screenshot(webDriver); | |
webDriver.findElement(By.xpath(".//button[contains(.,'Hello')]")).click(); | |
Thread.sleep(1000); | |
take_screenshot(webDriver); | |
js.executeScript("var elem=document.evaluate(\"//span[text()='My Profile']\",document.body, null, XPathResult.ANY_TYPE, null).iterateNext();elem.click();"); | |
// Thread.sleep(1000); | |
// take_screenshot(webDriver); | |
// ele = webDriver.findElement(By.id("PegaGadget0Ifr")); | |
// Thread.sleep(1000); | |
// take_screenshot(webDriver); | |
// webDriver.switchTo().frame((WebElement) webDriver.findElement(By.id("PegaGadget0Ifr"))); | |
webDriver.switchTo().defaultContent(); | |
Thread.sleep(5000); | |
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); | |
// File DestFile=new File("/Users/test/test.png"); | |
// FileUtils.copyFile(SrcFile, DestFile); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment