Skip to content

Instantly share code, notes, and snippets.

@garyjoy
Last active November 3, 2016 13:52
Show Gist options
  • Save garyjoy/7d041723379e1352cdccc0073e36001e to your computer and use it in GitHub Desktop.
Save garyjoy/7d041723379e1352cdccc0073e36001e to your computer and use it in GitHub Desktop.
/**
* Switch to the specified Frame
*
* @param frameName - This should be a Service/Dashboard name or a Task Subject
*/
public void switchToFrame(String frameName) {
log.message(String.format("Switching to '%s' iFrame", frameName));
// printFrameInformation();
TestFramework.driver.switchTo().defaultContent();
WebElement navigationFrame = findElement(getIframeLocator(PORTAL));
TestFramework.wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(navigationFrame));
WebElement serviceFrame = findElement(getIframeLocator(frameName));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(serviceFrame));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
}
/**
* Switch to the Task Frame
*/
protected void switchToTaskFrame() {
log.message("Switching to Task iFrame");
// printFrameInformation();
TestFramework.driver.switchTo().defaultContent();
WebElement navigationFrame = findElement(getIframeLocator(PORTAL));
TestFramework.wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(navigationFrame));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(1));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
}
/**
* Switch to the Service Frame
*/
protected void switchToServiceFrame() {
log.message("Switching to Service iFrame");
// printFrameInformation();
TestFramework.driver.switchTo().defaultContent();
WebElement navigationFrame = findElement(getIframeLocator(PORTAL));
TestFramework.wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(navigationFrame));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
TestFramework.longWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
}
/**
* Switch to the Navigation Frame
*/
protected void switchToNavigationFrame() {
log.message("Switching to Navigation iFrame");
// printFrameInformation();
TestFramework.driver.switchTo().defaultContent();
WebElement navigationFrame = findElement(getIframeLocator(PORTAL));
TestFramework.wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(navigationFrame));
}
// @SuppressWarnings("unused")
protected void printFrameInformation() {
TestFramework.driver.switchTo().defaultContent();
List < WebElement > iFrames = findElements(By.tagName("iframe"));
for (WebElement iFrame: iFrames) {
printRecursiveFrameInformation(iFrame, 0);
}
}
private void printRecursiveFrameInformation(WebElement iFrame, int depth) {
String indent = "";
for (int loop = 0; loop < depth; ++loop) {
indent += " ";
}
log.message(String.format("%sFrame: ID=%s Title=%s", indent, iFrame.getAttribute("id"),
iFrame.getAttribute("title")));
TestFramework.driver.switchTo().frame(iFrame);
List < WebElement > children = findElements(By.tagName("iframe"));
for (WebElement child: children) {
printRecursiveFrameInformation(child, depth + 1);
}
TestFramework.driver.switchTo().parentFrame();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment