… | |
… | |
77 | my $json = eval { require JSON::XS; JSON::XS:: } || do { require JSON::PP; JSON::PP:: }; |
77 | my $json = eval { require JSON::XS; JSON::XS:: } || do { require JSON::PP; JSON::PP:: }; |
78 | $json = $json->new->utf8; |
78 | $json = $json->new->utf8; |
79 | |
79 | |
80 | $json->boolean_values (0, 1) |
80 | $json->boolean_values (0, 1) |
81 | if $json->can ("boolean_values"); |
81 | if $json->can ("boolean_values"); |
|
|
82 | |
|
|
83 | sub _decode_base64 { |
|
|
84 | require MIME::Base64; |
|
|
85 | |
|
|
86 | MIME::Base64::decode_base64 (shift) |
|
|
87 | } |
82 | |
88 | |
83 | sub req_ { |
89 | sub req_ { |
84 | my ($self, $method, $ep, $body, $cb) = @_; |
90 | my ($self, $method, $ep, $body, $cb) = @_; |
85 | |
91 | |
86 | AnyEvent::HTTP::http_request $method => "$self->{_ep}$ep", |
92 | AnyEvent::HTTP::http_request $method => "$self->{_ep}$ep", |
… | |
… | |
1076 | |
1082 | |
1077 | =cut |
1083 | =cut |
1078 | |
1084 | |
1079 | =item $wd->take_screenshot |
1085 | =item $wd->take_screenshot |
1080 | |
1086 | |
1081 | Create a screenshot, returning it as a PNG image encoded as base64. To |
1087 | Create a screenshot, returning it as a PNG image. To decode and save, you |
1082 | decode and save, you coulöd do something like: |
1088 | coulöd do something like: |
1083 | |
1089 | |
1084 | use MIME::Base64 (); |
1090 | use MIME::Base64 (); |
1085 | |
1091 | |
1086 | my $screenshot = $wd->take_screenshot; |
1092 | my $screenshot = $wd->take_screenshot; |
1087 | |
1093 | |
… | |
… | |
1093 | |
1099 | |
1094 | Similar to C<take_screenshot>, but only takes a screenshot of the bounding |
1100 | Similar to C<take_screenshot>, but only takes a screenshot of the bounding |
1095 | box of a single element. |
1101 | box of a single element. |
1096 | |
1102 | |
1097 | Note: The W3C WebDriver specification also mentions a "scroll" parameter, |
1103 | Note: The W3C WebDriver specification also mentions a "scroll" parameter, |
1098 | but there is no way to specify it according to the spec, so it is |
1104 | but it is impossible to pass parameters for this command, so it is |
1099 | currently left out. |
1105 | czrrently left out. |
1100 | |
1106 | |
1101 | =cut |
1107 | =cut |
1102 | |
1108 | |
1103 | sub take_screenshot_ { |
1109 | sub take_screenshot_ { |
|
|
1110 | my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) }; |
1104 | $_[0]->get_ (screenshot => $_[1]); |
1111 | $_[0]->get_ (screenshot => $_[1]); |
1105 | } |
1112 | } |
1106 | |
1113 | |
1107 | sub take_element_screenshot_ { |
1114 | sub take_element_screenshot_ { |
|
|
1115 | my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) }; |
1108 | $_[0]->get_ ("element/$_[1]{$WEB_ELEMENT_IDENTIFIER}/screenshot" => $_[2]); |
1116 | $_[0]->get_ ("element/$_[1]{$WEB_ELEMENT_IDENTIFIER}/screenshot" => $_[2]); |
1109 | } |
1117 | } |
1110 | |
1118 | |
1111 | =back |
1119 | =back |
|
|
1120 | |
|
|
1121 | =head3 PRINT |
|
|
1122 | |
|
|
1123 | =over |
|
|
1124 | |
|
|
1125 | =cut |
|
|
1126 | |
|
|
1127 | =item $wd->print_page (key => value...) |
|
|
1128 | |
|
|
1129 | Create a printed version of the document, returning it as a PDF document |
|
|
1130 | encoded as base64. See C<take_screenshot> for an example on how to decode |
|
|
1131 | and save such a string. |
|
|
1132 | |
|
|
1133 | This command takes a lot of optional parameters, see L<the print |
|
|
1134 | section|https://www.w3.org/TR/webdriver2/#print> of the WebDriver |
|
|
1135 | specification for details. |
|
|
1136 | |
|
|
1137 | This command is taken from a draft document, so it might change in the |
|
|
1138 | future. |
|
|
1139 | |
|
|
1140 | =cut |
|
|
1141 | |
|
|
1142 | sub print_page { |
|
|
1143 | my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) }; |
|
|
1144 | $_[0]->post_ (print => { @_ }); |
|
|
1145 | } |
1112 | |
1146 | |
1113 | =head2 ACTION LISTS |
1147 | =head2 ACTION LISTS |
1114 | |
1148 | |
1115 | Action lists can be quite complicated. Or at least it took a while for |
1149 | Action lists can be quite complicated. Or at least it took a while for |
1116 | me to twist my head around them. Basically, an action list consists of a |
1150 | me to twist my head around them. Basically, an action list consists of a |
1117 | number of sources representing devices (such as a finger, a mouse, a pen |
1151 | number of sources representing devices (such as a finger, a mouse, a pen |
1118 | or a keyboard) and a list of actions for each source. |
1152 | or a keyboard) and a list of actions for each source, in a timeline. |
1119 | |
1153 | |
1120 | An action can be a key press, a pointer move or a pause (time delay). |
1154 | An action can be a key press, a pointer move or a pause (time delay). |
1121 | |
1155 | |
1122 | While you can provide these action lists manually, it is (hopefully) less |
1156 | While you can provide these action lists manually, it is (hopefully) less |
1123 | cumbersome to use the API described in this section to create them. |
1157 | cumbersome to use the API described in this section to create them. |
… | |
… | |
1128 | |
1162 | |
1129 | Most methods here are designed to chain, i.e. they return the web actions |
1163 | Most methods here are designed to chain, i.e. they return the web actions |
1130 | object, to simplify multiple calls. |
1164 | object, to simplify multiple calls. |
1131 | |
1165 | |
1132 | Also, while actions from different sources can happen "at the same time" |
1166 | Also, while actions from different sources can happen "at the same time" |
1133 | in the WebDriver protocol, this class ensures that actions will execute in |
1167 | in the WebDriver protocol, this class by default ensures that actions will |
1134 | the order specified. |
1168 | execute in the order specified. |
1135 | |
1169 | |
1136 | For example, to simulate a mouse click to an input element, followed by |
1170 | For example, to simulate a mouse click to an input element, followed by |
1137 | entering some text and pressing enter, you can use this: |
1171 | entering some text and pressing enter, you can use this: |
1138 | |
1172 | |
1139 | $wd->actions |
1173 | $wd->actions |
1140 | ->click (0, 100) |
1174 | ->click (0, 100) |
1141 | ->type ("some text") |
1175 | ->type ("some text") |
1142 | ->key ("{Enter}") |
1176 | ->key ("{Enter}") |
1143 | ->perform; |
1177 | ->perform; |
1144 | |
1178 | |
1145 | By default, keyboard and mouse input sources are provided. You can create |
1179 | By default, C<keyboard> and C<mouse> input sources are provided and |
1146 | your own sources and use them when adding events. The above example could |
1180 | used. You can create your own sources and use them when adding events. The |
1147 | be more verbosely written like this: |
1181 | above example could be more verbosely written like this: |
1148 | |
1182 | |
1149 | $wd->actions |
1183 | $wd->actions |
1150 | ->source ("mouse", "pointer", pointerType => "mouse") |
1184 | ->source ("mouse", "pointer", pointerType => "mouse") |
1151 | ->source ("kbd", "key") |
1185 | ->source ("kbd", "key") |
1152 | ->click (0, 100, "mouse") |
1186 | ->click (0, 100, "mouse") |
… | |
… | |
1155 | ->perform; |
1189 | ->perform; |
1156 | |
1190 | |
1157 | When you specify the event source explicitly it will switch the current |
1191 | When you specify the event source explicitly it will switch the current |
1158 | "focus" for this class of device (all keyboards are in one class, all |
1192 | "focus" for this class of device (all keyboards are in one class, all |
1159 | pointer-like devices such as mice/fingers/pens are in one class), so you |
1193 | pointer-like devices such as mice/fingers/pens are in one class), so you |
1160 | don't have to specify the source for subsequent actions. |
1194 | don't have to specify the source for subsequent actions that are on the |
|
|
1195 | same class. |
1161 | |
1196 | |
1162 | When you use the sources C<keyboard>, C<mouse>, C<touch1>..C<touch3>, |
1197 | When you use the sources C<keyboard>, C<mouse>, C<touch1>..C<touch3>, |
1163 | C<pen> without defining them, then a suitable default source will be |
1198 | C<pen> without defining them, then a suitable default source will be |
1164 | created for them. |
1199 | created for them. |
1165 | |
1200 | |