48
48
import org .openqa .selenium .WebDriver ;
49
49
import org .openqa .selenium .WebDriverException ;
50
50
import org .openqa .selenium .WebElement ;
51
+ import org .openqa .selenium .WindowType ;
51
52
import org .openqa .selenium .interactions .Actions ;
52
53
import org .openqa .selenium .interactions .Sequence ;
53
54
import org .openqa .selenium .remote .RemoteWebDriver ;
@@ -780,8 +781,8 @@ public void afterExecuteAsyncScript(
780
781
781
782
@ Test
782
783
void shouldFireTargetLocatorEvents () {
783
- WebDriver driver = mock (WebDriver . class );
784
- WebDriver .TargetLocator targetLocator = mock (WebDriver . TargetLocator . class );
784
+ WebDriver driver = mock ();
785
+ WebDriver .TargetLocator targetLocator = mock ();
785
786
when (driver .switchTo ()).thenReturn (targetLocator );
786
787
787
788
CollectorListener listener =
@@ -798,6 +799,49 @@ public void afterAnyTargetLocatorCall(
798
799
acc .append ("afterAnyTargetLocatorCall " ).append (method .getName ()).append ("\n " );
799
800
}
800
801
802
+ @ Override
803
+ public void beforeFrame (WebDriver .TargetLocator targetLocator , int index ) {
804
+ acc .append ("beforeFrame " ).append (index ).append ("\n " );
805
+ }
806
+
807
+ @ Override
808
+ public void afterFrame (
809
+ WebDriver .TargetLocator targetLocator , int index , WebDriver driver ) {
810
+ acc .append ("afterFrame " ).append (index ).append ("\n " );
811
+ }
812
+
813
+ @ Override
814
+ public void beforeFrame (WebDriver .TargetLocator targetLocator , String nameOrId ) {
815
+ acc .append ("beforeFrame " ).append (nameOrId ).append ("\n " );
816
+ }
817
+
818
+ @ Override
819
+ public void afterFrame (
820
+ WebDriver .TargetLocator targetLocator , String nameOrId , WebDriver driver ) {
821
+ acc .append ("afterFrame " ).append (nameOrId ).append ("\n " );
822
+ }
823
+
824
+ @ Override
825
+ public void beforeFrame (WebDriver .TargetLocator targetLocator , WebElement frameElement ) {
826
+ acc .append ("beforeFrame " ).append (frameElement ).append ("\n " );
827
+ }
828
+
829
+ @ Override
830
+ public void afterFrame (
831
+ WebDriver .TargetLocator targetLocator , WebElement frameElement , WebDriver driver ) {
832
+ acc .append ("afterFrame " ).append (frameElement ).append ("\n " );
833
+ }
834
+
835
+ @ Override
836
+ public void beforeParentFrame (WebDriver .TargetLocator targetLocator ) {
837
+ acc .append ("beforeParentFrame" ).append ("\n " );
838
+ }
839
+
840
+ @ Override
841
+ public void afterParentFrame (WebDriver .TargetLocator targetLocator , WebDriver driver ) {
842
+ acc .append ("afterParentFrame" ).append ("\n " );
843
+ }
844
+
801
845
@ Override
802
846
public void beforeWindow (WebDriver .TargetLocator targetLocator , String windowName ) {
803
847
acc .append ("beforeWindow " ).append (windowName ).append ("\n " );
@@ -808,11 +852,62 @@ public void afterWindow(
808
852
WebDriver .TargetLocator targetLocator , String windowName , WebDriver driver ) {
809
853
acc .append ("afterWindow " ).append (windowName ).append ("\n " );
810
854
}
855
+
856
+ @ Override
857
+ public void beforeNewWindow (WebDriver .TargetLocator targetLocator , WindowType typeHint ) {
858
+ acc .append ("beforeNewWindow " ).append (typeHint ).append ("\n " );
859
+ }
860
+
861
+ @ Override
862
+ public void afterNewWindow (
863
+ WebDriver .TargetLocator targetLocator , WindowType typeHint , WebDriver driver ) {
864
+ acc .append ("afterNewWindow " ).append (typeHint ).append ("\n " );
865
+ }
866
+
867
+ @ Override
868
+ public void beforeDefaultContent (WebDriver .TargetLocator targetLocator ) {
869
+ acc .append ("beforeDefaultContent" ).append ("\n " );
870
+ }
871
+
872
+ @ Override
873
+ public void afterDefaultContent (WebDriver .TargetLocator targetLocator , WebDriver driver ) {
874
+ acc .append ("afterDefaultContent" ).append ("\n " );
875
+ }
876
+
877
+ @ Override
878
+ public void beforeActiveElement (WebDriver .TargetLocator targetLocator ) {
879
+ acc .append ("beforeActiveElement" ).append ("\n " );
880
+ }
881
+
882
+ @ Override
883
+ public void afterActiveElement (WebDriver .TargetLocator targetLocator , WebDriver driver ) {
884
+ acc .append ("afterActiveElement" ).append ("\n " );
885
+ }
886
+
887
+ @ Override
888
+ public void beforeAlert (WebDriver .TargetLocator targetLocator ) {
889
+ acc .append ("beforeAlert" ).append ("\n " );
890
+ }
891
+
892
+ @ Override
893
+ public void afterAlert (WebDriver .TargetLocator targetLocator , Alert alert ) {
894
+ acc .append ("afterAlert" ).append ("\n " );
895
+ }
811
896
};
812
897
813
898
WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
814
-
815
- decorated .switchTo ().window ("windowName" );
899
+ WebDriver .TargetLocator decoratedTargetLocator = decorated .switchTo ();
900
+
901
+ decoratedTargetLocator .frame (3 );
902
+ decoratedTargetLocator .frame ("frame-id" );
903
+ WebElement frameElement = mock ();
904
+ decoratedTargetLocator .frame (frameElement );
905
+ decoratedTargetLocator .parentFrame ();
906
+ decoratedTargetLocator .window ("windowName" );
907
+ decoratedTargetLocator .newWindow (WindowType .TAB );
908
+ decoratedTargetLocator .defaultContent ();
909
+ decoratedTargetLocator .activeElement ();
910
+ decoratedTargetLocator .alert ();
816
911
817
912
assertThat (listener .acc .toString ().trim ())
818
913
.isEqualTo (
@@ -822,12 +917,60 @@ public void afterWindow(
822
917
"beforeAnyWebDriverCall switchTo" ,
823
918
"afterAnyWebDriverCall switchTo" ,
824
919
"afterAnyCall switchTo" ,
920
+ "beforeAnyCall frame" ,
921
+ "beforeAnyTargetLocatorCall frame" ,
922
+ "beforeFrame 3" ,
923
+ "afterFrame 3" ,
924
+ "afterAnyTargetLocatorCall frame" ,
925
+ "afterAnyCall frame" ,
926
+ "beforeAnyCall frame" ,
927
+ "beforeAnyTargetLocatorCall frame" ,
928
+ "beforeFrame frame-id" ,
929
+ "afterFrame frame-id" ,
930
+ "afterAnyTargetLocatorCall frame" ,
931
+ "afterAnyCall frame" ,
932
+ "beforeAnyCall frame" ,
933
+ "beforeAnyTargetLocatorCall frame" ,
934
+ "beforeFrame " + frameElement ,
935
+ "afterFrame " + frameElement ,
936
+ "afterAnyTargetLocatorCall frame" ,
937
+ "afterAnyCall frame" ,
938
+ "beforeAnyCall parentFrame" ,
939
+ "beforeAnyTargetLocatorCall parentFrame" ,
940
+ "beforeParentFrame" ,
941
+ "afterParentFrame" ,
942
+ "afterAnyTargetLocatorCall parentFrame" ,
943
+ "afterAnyCall parentFrame" ,
825
944
"beforeAnyCall window" ,
826
945
"beforeAnyTargetLocatorCall window" ,
827
946
"beforeWindow windowName" ,
828
947
"afterWindow windowName" ,
829
948
"afterAnyTargetLocatorCall window" ,
830
- "afterAnyCall window" ));
949
+ "afterAnyCall window" ,
950
+ "beforeAnyCall newWindow" ,
951
+ "beforeAnyTargetLocatorCall newWindow" ,
952
+ "beforeNewWindow tab" ,
953
+ "afterNewWindow tab" ,
954
+ "afterAnyTargetLocatorCall newWindow" ,
955
+ "afterAnyCall newWindow" ,
956
+ "beforeAnyCall defaultContent" ,
957
+ "beforeAnyTargetLocatorCall defaultContent" ,
958
+ "beforeDefaultContent" ,
959
+ "afterDefaultContent" ,
960
+ "afterAnyTargetLocatorCall defaultContent" ,
961
+ "afterAnyCall defaultContent" ,
962
+ "beforeAnyCall activeElement" ,
963
+ "beforeAnyTargetLocatorCall activeElement" ,
964
+ "beforeActiveElement" ,
965
+ "afterActiveElement" ,
966
+ "afterAnyTargetLocatorCall activeElement" ,
967
+ "afterAnyCall activeElement" ,
968
+ "beforeAnyCall alert" ,
969
+ "beforeAnyTargetLocatorCall alert" ,
970
+ "beforeAlert" ,
971
+ "afterAlert" ,
972
+ "afterAnyTargetLocatorCall alert" ,
973
+ "afterAnyCall alert" ));
831
974
}
832
975
833
976
@ Test
@@ -857,7 +1000,7 @@ public void beforeAnyWebDriverCall(WebDriver driver, Method method, Object[] arg
857
1000
}
858
1001
};
859
1002
860
- WebDriver decorated = new EventFiringDecorator (listener ).decorate (driver );
1003
+ WebDriver decorated = new EventFiringDecorator <> (listener ).decorate (driver );
861
1004
862
1005
assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
863
1006
}
0 commit comments