Browse Source

Not quite done yet, html5 bug on dnd

Emmanuel Peroumalnaik 11 years ago
parent
commit
76ef369f23

+ 14 - 6
lib/Selenium/Remote/Driver/ActionChains.pm

@@ -22,18 +22,18 @@ sub click {
     my $self = shift; 
     my $element = shift; 
     if ($element) { 
-        $self->driver->move_to(element => $element);
+       $self->move_to_element($element); 
     }
     # left click
     push @{$self->actions}, sub { $self->driver->click(0) };
     $self; 
 }
 
-sub click_and_hold_down { 
+sub click_and_hold { 
     my $self = shift; 
     my $element = shift; 
     if ($element) { 
-       $self->driver->move_to(element => $element); 
+       $self->move_to_element($element); 
     }
     push @{$self->actions}, sub { $self->driver->button_down };
     $self; 
@@ -43,7 +43,7 @@ sub context_click {
     my $self = shift; 
     my $element = shift; 
     if ($element) { 
-       $self->driver->move_to(element => $element); 
+       $self->move_to_element($element); 
     }
     # right click
     push @{$self->actions}, sub { $self->driver->click(2) }; 
@@ -55,7 +55,7 @@ sub double_click {
     my $self = shift; 
     my $element = shift; 
     if ($element) { 
-       $self->driver->move_to(element => $element); 
+       $self->move_to_element($element); 
     }
     push @{$self->actions}, sub { $self->driver->double_click };
     $self; 
@@ -65,7 +65,7 @@ sub release {
     my $self = shift; 
     my $element = shift; 
     if ($element) { 
-       $self->driver->move_to(element => $element); 
+       $self->move_to_element($element); 
     }
     push @{$self->actions}, sub { $self->driver->button_up };
     $self; 
@@ -79,5 +79,13 @@ sub drag_and_drop {
     $self; 
 }
 
+sub move_to_element {
+    my $self    = shift;
+    my $element = shift;
+    push @{ $self->actions },
+      sub { $self->driver->move_to( element => $element ) };
+    $self;
+}
+
 
 1;

+ 46 - 0
t/11-action-chains.t

@@ -0,0 +1,46 @@
+use strict;
+use warnings;
+
+use JSON;
+use Test::More;
+use Selenium::Remote::Driver;
+use Selenium::Remote::Mock::Commands;
+use Selenium::Remote::Mock::RemoteConnection;
+use Selenium::Remote::Driver::ActionChains;
+
+my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
+my $os  = $^O;
+if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
+    $os = 'linux';
+}
+my %selenium_args = ( 
+    browser_name => 'firefox'
+);
+
+
+my $mock_file = "11-action-chains-mock-$os.json";
+if (!$record && !(-e "t/mock-recordings/$mock_file")) {
+    plan skip_all => "Mocking of tests is not been enabled for this platform";
+}
+
+if ($record) { 
+    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
+}
+else { 
+    $selenium_args{remote_conn} =
+      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
+        replay_file => "t/mock-recordings/$mock_file" );
+}
+
+my $driver = Selenium::Remote::Driver->new(%selenium_args);
+my $action_chains = Selenium::Remote::Driver::ActionChains->new(driver => $driver);
+$driver->get('http://html5demos.com/drag');
+$driver->pause('1000');
+my $src = $driver->find_element('a#two', 'css'); 
+my $tgt = $driver->find_element('div#bin','css');
+$action_chains->drag_and_drop($src,$tgt)->perform();
+if ($record) { 
+    $driver->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
+}
+
+done_testing;

+ 29 - 0
t/mock-recordings/11-action-chains-mock-linux.json

@@ -0,0 +1,29 @@
+{
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/buttonup {}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 158\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":933658728}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/buttondown {}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 158\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":297666707}\n"
+   ],
+   "POST session {\"desiredCapabilities\":{\"acceptSslCerts\":true,\"browserName\":\"firefox\",\"javascriptEnabled\":true,\"platform\":\"ANY\",\"version\":\"\"}}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:18 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 545\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:22 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":{\"platform\":\"LINUX\",\"acceptSslCerts\":true,\"javascriptEnabled\":true,\"browserName\":\"firefox\",\"rotatable\":false,\"locationContextEnabled\":true,\"webdriver.remote.sessionid\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"version\":\"33.0\",\"cssSelectorsEnabled\":true,\"databaseEnabled\":true,\"handlesAlerts\":true,\"nativeEvents\":false,\"webStorageEnabled\":true,\"applicationCacheEnabled\":true,\"takesScreenshot\":true},\"state\":null,\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":2077443790}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/url {\"url\":\"http://html5demos.com/drag\"}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:22 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 158\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:25 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":745285224}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/moveto {\"element\":\"1\"}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 158\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":521065303}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/element {\"using\":\"css selector\",\"value\":\"a#two\"}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 170\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":{\"ELEMENT\":\"0\"},\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":1238886898}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/element {\"using\":\"css selector\",\"value\":\"div#bin\"}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 169\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":{\"ELEMENT\":\"1\"},\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":692495628}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/moveto {\"element\":\"0\"}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 158\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":442237451}\n"
+   ],
+   "POST session/79f6b4ac-51f4-4ef2-ad45-a5876a8dee15/click {\"button\":0}" : [
+      "HTTP/1.1 200 OK\nCache-Control: no-cache\nCache-Control: no-cache\nConnection: close\nDate: Wed, 22 Oct 2014 08:36:26 GMT\nServer: Jetty/5.1.x (Linux/3.13.0-34-generic amd64 java/1.6.0_33\nContent-Length: 159\nContent-Type: application/json; charset=utf-8\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\nClient-Date: Wed, 22 Oct 2014 08:36:26 GMT\nClient-Peer: 127.0.0.1:4444\nClient-Response-Num: 1\n\n{\"status\":0,\"sessionId\":\"79f6b4ac-51f4-4ef2-ad45-a5876a8dee15\",\"value\":null,\"state\":\"success\",\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":2065196531}\n"
+   ]
+}