When executing a Selenium test with ChromeDriver, I would like to bring the test browser into focus to see the actions taking place. The way I am able to do that now is by manually clicking the instance of Chrome -- otherwise, the tests do run, I just don't see them taking place. I'd love for the focus part to happen automatically.
My testing environment looks like this:
- Operating System: OS X(El Capitan)
- IDE: IntelliJ 15 - community edition
- Selenium version 2.48
- Java JDK: 1.8
- JUnit: 4.11 ChromeDriver: 2.2
FYI, I have tried this with no luck (a common answer on StackOverflow):
String currentWindow = driver.getWindowHandle();
driver.switchTo().window(currentWindow);
Current code:
public class TestLogin {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "/Users/*******/Downloads/chromedriver");
driver = new ChromeDriver();
}
@Test
public void succeeded() {
driver.get("http://the-internet.herokuapp.com/login");
String currentWindow = driver.getWindowHandle();
driver.switchTo().window(currentWindow);
driver.findElement(By.id("username")).sendKeys("tomsmith");
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!");
driver.findElement(By.cssSelector("button")).click();
}
@After
public void tearDown() {
driver.quit();
}
}