-
-
Save FROGGS/8717727b20b18e6ea785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Test; | |
use lib 'lib'; | |
# Methods to test | |
my @methods = 'url', 'source', 'move-to', 'click', 'quit', | |
'screenshot', 'save-screenshot', 'forward', 'back', 'refresh', | |
'element-by-class', 'element-by-css', 'element-by-id', | |
'element-by-name', 'element-by-link-text', 'element-by-partial-link-text', | |
'element-by-tag-name', 'element-by-xpath', 'elements-by-class', | |
'elements-by-css', 'elements-by-id', 'elements-by-name', | |
'elements-by-link-text', 'elements-by-partial-link-text', | |
'elements-by-tag-name', 'elements-by-xpath', 'sessions', 'capabilities', | |
'script-timeout', 'implicit-timeout', 'page-load-timeout', | |
'current-window', 'windows', 'status', | |
'async-script-timeout', 'implicit-wait-timeout', 'execute', 'execute-async', | |
'ime-available-engines', 'ime-active-engine', 'ime-activated', | |
'ime-activated', 'ime-activated', 'frame', 'frame-parent', | |
'cookies', 'cookie', 'delete-all-cookies', 'delete-cookie', | |
'send-keys-to-active-element', 'orientation', 'alert-text', 'accept-alert', | |
'dismiss-alert', 'button-down', 'button-up', 'double-click', 'touch-click', | |
'touch-down', 'touch-up', 'touch-move', 'touch-scroll', 'touch-double-click', | |
'touch-long-click', 'touch-flick', 'location', | |
'local-storage', 'add-to-local-storage', 'clear-local-storage', | |
'get-from-local-storage', 'delete-from-local-storage', 'local-storage-size', | |
'session-storage', 'add-to-session-storage', 'clear-session-storage', | |
'get-from-session-storage', 'delete-from-session-storage', | |
'session-storage-size', 'log', 'log-types', 'application-cache-status'; | |
plan @methods.elems + 10; | |
use Selenium::WebDriver::BlackBerry; | |
ok 1, "'use Selenium::WebDriver::BlackBerry' worked!"; | |
#~ { | |
#~ # Skip tests if firefox is not found | |
#~ use File::Which; | |
#~ unless which('firefox') { | |
#~ skip-rest("Firefox is not installed. skipping tests..."); | |
#~ exit; | |
#~ } | |
#~ } | |
my $driver = Selenium::WebDriver::BlackBerry.new("169.254.0.1"); | |
ok $driver, "Selenium::WebDriver::BlackBerry.new worked"; | |
for @methods -> $method { | |
ok Selenium::WebDriver::BlackBerry.can($method), | |
"Selenium::WebDriver::BlackBerry.$method is found"; | |
} | |
#{ | |
# my $sessions = $driver.sessions; | |
# ok $sessions.defined, "Sessions returned a defined value"; | |
# ok $sessions ~~ Array, "Sessions is an array"; | |
# ok $sessions.elems == 1, "Only One session should be there"; | |
# ok $sessions[0]<id> ~~ Str, "And we have a sessionId"; | |
#} | |
{ | |
my $capabilities = $driver.capabilities; | |
ok $capabilities.defined, "capabilities returned a defined value"; | |
ok $capabilities ~~ Hash, "capabilities is a hash"; | |
ok $capabilities<sessionId> ~~ Str, "And we have a sessionId"; | |
} | |
{ | |
my $current-window = $driver.current-window; | |
ok $current-window.defined, "current-window returned a defined value"; | |
ok $current-window.handle ~~ Str, "current-window handle is a string"; | |
} | |
{ | |
my @windows = $driver.windows; | |
ok @windows.defined, "windows returned a defined value"; | |
ok @windows.elems > 0, "windows has at least one active window"; | |
ok @windows[0] ~~ Selenium::WebDriver::WebWindow, "first element is a window"; | |
} | |
$driver.url("http://google.de"); | |
#~ say $driver.title; | |
my ($input) = $driver.elements-by-name('q'); | |
$input.send-keys('Hello World'); | |
#~ LEAVE { | |
#~ $driver.quit if $driver.defined; | |
#~ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Selenium::WebDriver::Wire; | |
unit class Selenium::WebDriver::BlackBerry is Selenium::WebDriver::Wire; | |
method new( | |
Str $host, | |
Int :$port = 1338, | |
Bool :$debug = False ) | |
{ | |
self.bless: :$host, :$port, :$debug | |
} | |
method start { | |
say "Launching BlackBerry Driver on $.host():$.port()" if self.debug; | |
} | |
method stop { | |
} | |
# GET /sessions | |
method sessions { | |
my $result = self._execute-command( "GET", "/sessions" ); | |
return unless $result.defined; | |
return $result; | |
} | |
method _new-session { | |
my $sessions = self.sessions; | |
if $sessions -> [$s] { | |
return { sessionId => ~$s<id> } | |
} | |
return self._execute-command( | |
"POST", | |
"/session", | |
{ | |
"desiredCapabilities" => {}, | |
"requiredCapabilities" => {}, | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Selenium/WebDriver/Wire.pm6 b/lib/Selenium/WebDriver/Wire.pm6 | |
index a1e199f..89b524e 100644 | |
--- a/lib/Selenium/WebDriver/Wire.pm6 | |
+++ b/lib/Selenium/WebDriver/Wire.pm6 | |
@@ -28,9 +28,9 @@ has Str $.session-id is rw; | |
=begin markdown | |
=end markdown | |
submethod BUILD( | |
- Str $host = '127.0.0.1', | |
+ Str :$host = '127.0.0.1', | |
Int :$port = -1, | |
- Str :$url-prefix = ''; | |
+ Str :$url-prefix = '', | |
Bool :$debug = False ) | |
{ | |
@@ -440,7 +440,7 @@ method element-by-xpath(Str $xpath) { | |
=end markdown | |
# POST /session/:sessionId/elements | |
method _elements(Str $using, Str $value) { | |
- my @elements = self._post( | |
+ my $elements = self._post( | |
"elements", | |
{ | |
'using' => $using, | |
@@ -448,13 +448,12 @@ method _elements(Str $using, Str $value) { | |
} | |
); | |
- return unless @elements.defined; | |
- my @results = gather { | |
- take Selenium::WebDriver::WebElement.new( | |
- :id( $_<value><ELEMENT> ), | |
- :driver( self ) | |
- ) for @elements; | |
- }; | |
+ my @results = $elements<value>.map({ | |
+ Selenium::WebDriver::WebElement.new( | |
+ :id( $_<ELEMENT> ), | |
+ :driver( self ) | |
+ ) | |
+ }); | |
return @results; | |
} | |
@@ -721,14 +720,14 @@ method _die(Str $method, Str $command, $response) { | |
say "Died while doing '$method $command', content:\n"; | |
say $response.content if $response.defined; | |
say "end of content\n"; | |
- my $o = from-json($response.content); | |
+ #~ my $o = from-json($response.content); | |
- my $error = $o<value>; | |
- Selenium::WebDriver::X::Error.new( | |
- reason => $error<message>, | |
- screenshot => $error<screen>, | |
- class => $error<class> | |
- ).throw; | |
+ #~ my $error = $o<value>; | |
+ #~ Selenium::WebDriver::X::Error.new( | |
+ #~ reason => $error<message>, | |
+ #~ screenshot => $error<screen>, | |
+ #~ class => $error<class> | |
+ #~ ).throw; | |
} | |
=begin markdown | |
=end markdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment