Skip to content

Commit 10af32c

Browse files
committed
[bidi] [java] Update iframe related tests to actions
1 parent 7ddd002 commit 10af32c

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

java/test/org/openqa/selenium/bidi/input/CombinedInputActionsTest.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
import static org.openqa.selenium.testing.drivers.Browser.IE;
3333
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
3434

35+
import java.util.ArrayList;
3536
import java.util.List;
37+
import java.util.Optional;
38+
39+
import org.assertj.core.api.AssertionsForClassTypes;
3640
import org.junit.jupiter.api.BeforeEach;
3741
import org.junit.jupiter.api.Test;
3842
import org.openqa.selenium.By;
@@ -44,6 +48,11 @@
4448
import org.openqa.selenium.WaitingConditions;
4549
import org.openqa.selenium.WebElement;
4650
import org.openqa.selenium.bidi.Input;
51+
import org.openqa.selenium.bidi.Script;
52+
import org.openqa.selenium.bidi.script.EvaluateResult;
53+
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
54+
import org.openqa.selenium.bidi.script.LocalValue;
55+
import org.openqa.selenium.bidi.script.WindowProxyProperties;
4756
import org.openqa.selenium.interactions.Actions;
4857
import org.openqa.selenium.interactions.PointerInput;
4958
import org.openqa.selenium.testing.JupiterTestBase;
@@ -248,17 +257,11 @@ private void navigateToClicksPageAndClickLink() {
248257
wait.until(titleIs("XHTML Test Page"));
249258
}
250259

251-
// Error {"type":"error","id":2,"error":"no such element","message":"No element found for shared
252-
// id"}
253-
// TODO: Need to figure out passing script.SharedReference for frames i.e. handleId for the frame
254-
// The main concern is passing in the context for the iframe to run the command in
255260
@SwitchToTopAfterTest
256261
@Test
257262
@NotYetImplemented(SAFARI)
258263
@NotYetImplemented(IE)
259264
@NotYetImplemented(EDGE)
260-
@NotYetImplemented(FIREFOX)
261-
@NotYetImplemented(CHROME)
262265
void canMoveMouseToAnElementInAnIframeAndClick() {
263266
driver.get(appServer.whereIs("click_tests/click_in_iframe.html"));
264267

@@ -267,10 +270,34 @@ void canMoveMouseToAnElementInAnIframeAndClick() {
267270

268271
WebElement link = driver.findElement(By.id("link"));
269272

270-
// This needs to the browsing context of the frame
271-
input.perform(windowHandle, new Actions(driver).moveToElement(link).click().getSequences());
273+
try (Script script = new Script(driver)) {
274+
275+
List<LocalValue> arguments = new ArrayList<>();
276+
277+
EvaluateResult result =
278+
script.callFunctionInBrowsingContext(
279+
driver.getWindowHandle(),
280+
"() => document.querySelector('iframe[id=\"ifr\"]').contentWindow",
281+
false,
282+
Optional.of(arguments),
283+
Optional.empty(),
284+
Optional.empty());
285+
286+
assertThat(result.getResultType()).isEqualTo(EvaluateResult.Type.SUCCESS);
287+
assertThat(result.getRealmId()).isNotNull();
272288

273-
wait.until(titleIs("Submitted Successfully!"));
289+
EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
290+
291+
WindowProxyProperties window =
292+
(WindowProxyProperties) successResult.getResult().getValue().get();
293+
294+
String frameBrowsingContext = window.getBrowsingContext();
295+
296+
input.perform(
297+
frameBrowsingContext, new Actions(driver).moveToElement(link).click().getSequences());
298+
299+
wait.until(titleIs("Submitted Successfully!"));
300+
}
274301
}
275302

276303
@Test

java/test/org/openqa/selenium/bidi/input/DefaultMouseTest.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
3232

3333
import java.time.Duration;
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
import java.util.Optional;
37+
3438
import org.junit.jupiter.api.BeforeEach;
3539
import org.junit.jupiter.api.Test;
3640
import org.openqa.selenium.By;
@@ -41,6 +45,11 @@
4145
import org.openqa.selenium.WebDriver;
4246
import org.openqa.selenium.WebElement;
4347
import org.openqa.selenium.bidi.Input;
48+
import org.openqa.selenium.bidi.Script;
49+
import org.openqa.selenium.bidi.script.EvaluateResult;
50+
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
51+
import org.openqa.selenium.bidi.script.LocalValue;
52+
import org.openqa.selenium.bidi.script.WindowProxyProperties;
4453
import org.openqa.selenium.interactions.Actions;
4554
import org.openqa.selenium.support.Color;
4655
import org.openqa.selenium.support.Colors;
@@ -255,17 +264,39 @@ void testMoveAndClick() {
255264
@NotYetImplemented(SAFARI)
256265
@NotYetImplemented(IE)
257266
@NotYetImplemented(EDGE)
258-
@NotYetImplemented(CHROME)
259-
@NotYetImplemented(FIREFOX)
260-
// ToDo: Figure out how to get the frame's context id and use that
261267
void testShouldClickElementInIFrame() {
262268
driver.get(pages.clicksPage);
263269
driver.switchTo().frame("source");
264270
WebElement element = driver.findElement(By.id("otherframe"));
265-
inputModule.perform(
266-
driver.getWindowHandle(), getBuilder(driver).moveToElement(element).click().getSequences());
267-
driver.switchTo().defaultContent().switchTo().frame("target");
268-
wait.until(elementTextToEqual(By.id("span"), "An inline element"));
271+
272+
try (Script script = new Script(driver)) {
273+
274+
List<LocalValue> arguments = new ArrayList<>();
275+
276+
EvaluateResult result =
277+
script.callFunctionInBrowsingContext(
278+
driver.getWindowHandle(),
279+
"() => document.querySelector('iframe[id=\"source\"]').contentWindow",
280+
false,
281+
Optional.of(arguments),
282+
Optional.empty(),
283+
Optional.empty());
284+
285+
assertThat(result.getResultType()).isEqualTo(EvaluateResult.Type.SUCCESS);
286+
assertThat(result.getRealmId()).isNotNull();
287+
288+
EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
289+
290+
WindowProxyProperties window =
291+
(WindowProxyProperties) successResult.getResult().getValue().get();
292+
293+
String frameBrowsingContext = window.getBrowsingContext();
294+
295+
inputModule.perform(
296+
frameBrowsingContext, getBuilder(driver).moveToElement(element).click().getSequences());
297+
driver.switchTo().defaultContent().switchTo().frame("target");
298+
wait.until(elementTextToEqual(By.id("span"), "An inline element"));
299+
}
269300
}
270301

271302
@Test

0 commit comments

Comments
 (0)