Skip to content

Commit

Permalink
Migrated By.id() to By.cssSelector() to work with Chrome Mobile 75.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Sep 26, 2020
1 parent 13782c4 commit 08e04c1
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/test/java/com/aerokube/selenoid/TestAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class TestAttributes extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.SECOND);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Capability to get element attributes")
@Test
public void testGetAttributes() throws Exception {
WebDriver driver = getDriver();
WebElement div = driver.findElement(By.id("test-id"));
WebElement div = driver.findElement(By.cssSelector("#test-id"));
assertThat(div.getSize().getWidth(), equalTo(100));
assertThat(div.getSize().getHeight(), equalTo(100));
assertThat(div.getLocation().getX(), equalTo(100));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/aerokube/selenoid/TestCookies.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import static org.junit.Assert.assertThat;

public class TestCookies extends TestBase {


@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Working with cookies")
Expand All @@ -39,5 +39,5 @@ public void testCookie() throws Exception {
fail("Cookies are not supported", e);
}
}

}
4 changes: 2 additions & 2 deletions src/test/java/com/aerokube/selenoid/TestDrag.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class TestDrag extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.DRAG);
waitUntilElementIsPresent(By.id("custom-handle"));
waitUntilElementIsPresent(By.cssSelector("#custom-handle"));
}

@Features("Drag functionality")
@Test
public void testDrag() throws Exception {
try {
WebDriver driver = getDriver();
WebElement button = driver.findElement(By.id("custom-handle"));
WebElement button = driver.findElement(By.cssSelector("#custom-handle"));
assertThat(button.getText(), equalTo("10"));

Actions drag = new Actions(driver);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/aerokube/selenoid/TestEvaluateJavascript.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestEvaluateJavascript extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
WebDriver driver = getDriver();
assertThat("Javascript execution is not supported", driver, is(instanceOf(JavascriptExecutor.class)));
}
Expand All @@ -42,7 +42,7 @@ public void testEvaluateJavascript() throws Exception {
fail("Synchronous javascript execution is not supported", e);
}
}

@Features("Asynchronous Javascript evaluation")
@Test
public void testEvaluateJavascriptAsync() throws Exception {
Expand All @@ -61,7 +61,7 @@ public void testEvaluateJavascriptAsync() throws Exception {
fail("Asynchronous javascript execution is not supported");
}
}

@Features("Window scrolling")
@Test
public void testScroll() throws Exception {
Expand All @@ -73,15 +73,15 @@ public void testScroll() throws Exception {
fail("Window scrolling is not supported", e);
}
}

private String getScript() {
return "var div = document.getElementById('test-id'); div.textContent = 'bar';";
}

private String getAsyncScript() {
return "var callback = arguments[arguments.length - 1];" +
" var div = document.getElementById('test-id');" +
" div.textContent = 'baz'; callback('works');";
}

}
8 changes: 4 additions & 4 deletions src/test/java/com/aerokube/selenoid/TestFindElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TestFindElement extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Finding element by CSS selector")
Expand All @@ -39,7 +39,7 @@ public void testFindByCSSSelector() throws Exception {
@Test
public void testFindById() throws Exception {
WebDriver driver = getDriver();
List<WebElement> elementsById = driver.findElements(By.id("test-id"));
List<WebElement> elementsById = driver.findElements(By.cssSelector("#test-id"));
assertThat(elementsById, hasSize(1));
assertThat(elementsById.get(0).getTagName(), equalToIgnoringCase("div"));
assertThat(elementsById.get(0).getText(), equalTo("foo"));
Expand All @@ -54,7 +54,7 @@ public void testFindByClass() throws Exception {
assertThat(elementsByClass.get(0).getTagName(), equalToIgnoringCase("span"));
assertThat(elementsByClass.get(0).getText(), equalTo("bar"));
}

@Features("Finding element by XPath expression")
@Test
public void testFindByXPath() throws Exception {
Expand All @@ -64,5 +64,5 @@ public void testFindByXPath() throws Exception {
assertThat(elementsByXPath.get(0).getTagName(), equalToIgnoringCase("span"));
assertThat(elementsByXPath.get(0).getText(), equalTo("bar"));
}

}
6 changes: 3 additions & 3 deletions src/test/java/com/aerokube/selenoid/TestHotkeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public class TestHotkeys extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.HOTKEYS);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Pressing keys on the keyboard")
@Test
public void testHotkeys() {
WebDriver driver = getDriver();
String someKeys = Keys.chord(Keys.CONTROL, "c");
WebElement divTag = driver.findElement(By.id("test-id"));
WebElement divTag = driver.findElement(By.cssSelector("#test-id"));
assertThat(divTag.getText(), equalTo("initial"));
driver.findElement(By.tagName("html")).sendKeys(someKeys);
assertThat(divTag.getText(), equalTo("new"));
}

}
6 changes: 3 additions & 3 deletions src/test/java/com/aerokube/selenoid/TestScreenshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TestScreenshot extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Taking screenshots")
Expand All @@ -30,11 +30,11 @@ public void testScreenshot() throws Exception {
fail("Screenshots are not supported", e);
}
}

@Attachment("screenshot")
private byte[] takeScreenshot(WebDriver driver) {
return ((TakesScreenshot) new Augmenter().augment(driver))
.getScreenshotAs(OutputType.BYTES);
}

}
6 changes: 3 additions & 3 deletions src/test/java/com/aerokube/selenoid/TestTimeouts.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TestTimeouts extends TestBase {
@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Setting page load timeout")
Expand All @@ -30,7 +30,7 @@ public void testPageLoadTimeout() throws Exception {
fail("Setting page load timeout is not supported", e);
}
}

@Features("Setting implicit timeout")
@Test
public void testImplicitTimeout() throws Exception {
Expand All @@ -41,7 +41,7 @@ public void testImplicitTimeout() throws Exception {
fail("Implicitly waiting is not supported", e);
}
}

@Features("Setting script execution timeout")
@Test
public void testScriptTimeout() throws Exception {
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/com/aerokube/selenoid/TestWindowCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

@Features("Miscellaneous window commands")
public class TestWindowCommands extends TestBase {

@Before
public void before() throws Exception {
openPage(Page.FIRST);
waitUntilElementIsPresent(By.id("test-id"));
waitUntilElementIsPresent(By.cssSelector("#test-id"));
}

@Features("Closing window")
@Test
public void testWindowCloseIsSupported() throws Exception {
try {
WebDriver driver = getDriver();
WebElement link = driver.findElement(By.id("test-link")); //This link opens new window
WebElement link = driver.findElement(By.cssSelector("#test-link")); //This link opens new window
link.click();
await().until(() -> getDriver().getWindowHandles().size() == 2);
getDriver().close();
Expand All @@ -38,13 +38,13 @@ public void testWindowCloseIsSupported() throws Exception {
fail("WebDriver.close() is not supported", e);
}
}

@Features("Switching between windows")
@Test
public void testSwitchWindows() throws Exception {
try {
WebDriver driver = getDriver();
WebElement link = driver.findElement(By.id("test-link")); //This link opens new window
WebElement link = driver.findElement(By.cssSelector("#test-link")); //This link opens new window
link.click();
await().until(() -> driver.getWindowHandles().size() == 2);
List<String> windowNames = driver.getWindowHandles().stream().map(wh -> {
Expand All @@ -56,20 +56,20 @@ public void testSwitchWindows() throws Exception {
fail("Switching between windows is not supported", e);
}
}

@Features("Switching between frames")
@Test
public void testSwitchFrames() throws Exception {
try {
openPage(Page.FRAMES);
WebDriver driver = getDriver();
WebElement firstFrameElement = driver.findElement(By.id("first"));
WebElement firstFrameElement = driver.findElement(By.cssSelector("#first"));
driver.switchTo().frame(firstFrameElement);
WebElement firstFrame = driver.switchTo().activeElement();
assertThat(firstFrame.findElements(By.cssSelector("span.test-class")), hasSize(1));

driver.switchTo().defaultContent();
WebElement secondFrameElement = driver.findElement(By.id("second"));
WebElement secondFrameElement = driver.findElement(By.cssSelector("#second"));
driver.switchTo().frame(secondFrameElement);
WebElement secondFrame = driver.switchTo().activeElement();
assertThat(secondFrame.findElements(By.cssSelector("div#test-id")), hasSize(1));
Expand All @@ -78,7 +78,7 @@ public void testSwitchFrames() throws Exception {
fail("Switching between frames is not supported", e);
}
}

@Features("Navigating back and forward")
@Test
public void testBackAndForward() throws Exception {
Expand All @@ -91,7 +91,7 @@ public void testBackAndForward() throws Exception {
driver.navigate().forward();
assertThat(getPageTitle(), equalTo("second"));
}

@Features("Screen orientation support")
@Ignore
@Test
Expand All @@ -108,5 +108,5 @@ public void testScreenOrientation() {
fail("This driver does not support rotation", e);
}
}

}

0 comments on commit 08e04c1

Please sign in to comment.