Created
May 1, 2018 18:22
-
-
Save ckzgraphics/e68a17575526f892f7b13d247ffc930b to your computer and use it in GitHub Desktop.
Use 'nativeWebTap' capability to ensure iOS opens a new tab / window after clicking the button
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
package com.bs.mobile.web; | |
import java.io.File; | |
import java.net.URL; | |
import java.util.Calendar; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.TimeZone; | |
import org.apache.commons.io.FileUtils; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.Capabilities; | |
import org.openqa.selenium.JavascriptExecutor; | |
import org.openqa.selenium.Keys; | |
import org.openqa.selenium.OutputType; | |
import org.openqa.selenium.TakesScreenshot; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeOptions; | |
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 switch_to_web_iPhone { | |
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; | |
// AndroidDriver<WebElement> webDriver = null; | |
// IOSDriver<WebElement> webDriver = null; | |
ChromeOptions options = null; | |
WebDriverWait wait = null; | |
Actions act = null; | |
String AUT_URL = "http://toolsqa.com/automation-practice-switch-windows/"; | |
URL URLObj = null; | |
DesiredCapabilities caps = null; | |
try { | |
URLObj = new URL(HUB_URL); | |
caps = new DesiredCapabilities(); | |
caps.setCapability("browserName", "iPhone"); | |
caps.setCapability("device", "iPhone 7"); | |
caps.setCapability("realMobile", "true"); | |
caps.setCapability("os_version", "10.3"); | |
//caps.setCapability(ChromeOptions.CAPABILITY, options); | |
caps.setCapability("build", "Support Automate"); | |
caps.setCapability("name", "Test Switch To Window"); | |
// caps.setCapability("browserstack.timezone", "UTC"); | |
caps.setCapability("browserstack.local", "false"); | |
caps.setCapability("browserstack.localIdentifier", "Test123"); | |
caps.setCapability("browserstack.debug", "true"); | |
caps.setCapability("browserstack.video", "true"); | |
caps.setCapability("browserstack.networkLogs", "true"); | |
caps.setCapability("nativeWebTap", "true"); | |
// caps.setCapability("browserstack.ie.driver", "2.53.1"); | |
webDriver = new RemoteWebDriver(URLObj, caps); | |
// webDriver = new AndroidDriver<WebElement>(URLObj, caps); | |
// webDriver = new IOSDriver<WebElement>(URLObj, caps); | |
wait = new WebDriverWait(webDriver, 10000); | |
act = new Actions(webDriver); | |
js = (JavascriptExecutor)webDriver; | |
webDriver.get(AUT_URL); | |
System.out.println("TITLE :: " + webDriver.getTitle()); | |
Thread.sleep(3000); | |
webDriver.findElement(By.xpath(".//button[contains(.,'New Browser Window')]")).click(); | |
Thread.sleep(4000); | |
Set<String> wind = webDriver.getWindowHandles(); | |
String news = ""; | |
for (String string : wind) { | |
System.out.println("WINDW :: " + string); | |
news = string; | |
} | |
webDriver.switchTo().window(news); | |
System.out.println("TITLE :: " + webDriver.getTitle()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
if(webDriver != null){ | |
webDriver.quit(); | |
} | |
} // TRY END | |
} // MAIN END | |
} // CLASS END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment