1919import io .appium .java_client .ios .IOSDriver ;
2020import io .appium .java_client .ios .options .XCUITestOptions ;
2121import org .junit .jupiter .api .Test ;
22+ import org .openqa .selenium .By ;
2223import org .openqa .selenium .Capabilities ;
24+ import org .openqa .selenium .NoSuchSessionException ;
25+ import org .openqa .selenium .WebElement ;
2326import org .openqa .selenium .remote .RemoteWebDriver ;
27+ import org .openqa .selenium .remote .RemoteWebElement ;
2428import org .openqa .selenium .remote .UnreachableBrowserException ;
2529
2630import java .lang .reflect .Method ;
2731import java .net .MalformedURLException ;
2832import java .net .URL ;
33+ import java .util .ArrayList ;
2934import java .util .Collections ;
35+ import java .util .List ;
3036import java .util .concurrent .Callable ;
3137
3238import static io .appium .java_client .proxy .Helpers .createProxy ;
@@ -45,6 +51,31 @@ public FakeIOSDriver(URL url, Capabilities caps) {
4551 @ Override
4652 protected void startSession (Capabilities capabilities ) {
4753 }
54+
55+ @ Override
56+ public WebElement findElement (By locator ) {
57+ RemoteWebElement webElement = new RemoteWebElement ();
58+ webElement .setId (locator .toString ());
59+ webElement .setParent (this );
60+ return webElement ;
61+ }
62+
63+ @ Override
64+ public List <WebElement > findElements (By locator ) {
65+ List <WebElement > webElements = new ArrayList <>();
66+
67+ RemoteWebElement webElement1 = new RemoteWebElement ();
68+ webElement1 .setId ("1234" );
69+ webElement1 .setParent (this );
70+ webElements .add (webElement1 );
71+
72+ RemoteWebElement webElement2 = new RemoteWebElement ();
73+ webElement2 .setId ("5678" );
74+ webElement2 .setParent (this );
75+ webElements .add (webElement2 );
76+
77+ return webElements ;
78+ }
4879 }
4980
5081 @ Test
@@ -133,4 +164,52 @@ public Object onError(Object obj, Method method, Object[] args, Throwable e) thr
133164 "onError get" )
134165 )));
135166 }
167+
168+
169+ @ Test
170+ void shouldFireEventsForRemoteWebElement () throws MalformedURLException {
171+ final StringBuilder acc = new StringBuilder ();
172+ MethodCallListener listener = new MethodCallListener () {
173+ @ Override
174+ public void beforeCall (Object target , Method method , Object [] args ) {
175+ acc .append ("beforeCall " ).append (method .getName ()).append ("\n " );
176+ }
177+ };
178+
179+ FakeIOSDriver driver = createProxy (
180+ FakeIOSDriver .class ,
181+ new Object [] {new URL ("http://localhost:4723/" ), new XCUITestOptions ()},
182+ new Class [] {URL .class , Capabilities .class },
183+ listener
184+ );
185+
186+ WebElement element = driver .findElement (By .id ("button" ));
187+
188+ assertThrows (
189+ NoSuchSessionException .class ,
190+ element ::click
191+ );
192+
193+ List <WebElement > elements = driver .findElements (By .id ("button" ));
194+
195+ assertThrows (
196+ NoSuchSessionException .class ,
197+ () -> elements .get (1 ).isSelected ()
198+ );
199+
200+ assertThat (acc .toString ().trim (), is (equalTo (
201+ String .join ("\n " ,
202+ "beforeCall findElement" ,
203+ "beforeCall click" ,
204+ "beforeCall getSessionId" ,
205+ "beforeCall getCapabilities" ,
206+ "beforeCall getCapabilities" ,
207+ "beforeCall findElements" ,
208+ "beforeCall isSelected" ,
209+ "beforeCall getSessionId" ,
210+ "beforeCall getCapabilities" ,
211+ "beforeCall getCapabilities"
212+ )
213+ )));
214+ }
136215}
0 commit comments