Skip to content

Commit 18a4c0d

Browse files
committed
LukeIS: iphone driver adding 'Status' response in order to attach to a Grid. Adding settings to specify where Grid is located in order to attach to the Grid on startup of app. Removing and ignoring iphone/.../atoms.h as it is autogenerated, updated script to detect for existance of atoms.h as to not rebuild every time. Adding new DesiredCapabilities.IPAD, had to add '/status' to DriverCommand and HttpCommandExecutor to easily test status command. fixes issue 1882
r14831
1 parent a79985d commit 18a4c0d

File tree

18 files changed

+318
-4437
lines changed

18 files changed

+318
-4437
lines changed

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ desc 'Clean build artifacts.'
227227
task :clean do
228228
rm_rf 'build/'
229229
rm_rf 'iphone/build/'
230+
rm_rf 'iphone/src/objc/atoms.h'
230231
rm_rf 'android/app/bin/'
231232
rm_rf 'android/app/build/'
232233
rm_rf 'android/app/libs/'

iphone/Settings.bundle/Root.plist

+42
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,48 @@
3030
<key>AutocorrectionType</key>
3131
<string>No</string>
3232
</dict>
33+
<dict>
34+
<key>Type</key>
35+
<string>PSGroupSpecifier</string>
36+
<key>Title</key>
37+
<string>Grid</string>
38+
</dict>
39+
<dict>
40+
<key>Type</key>
41+
<string>PSTextFieldSpecifier</string>
42+
<key>Title</key>
43+
<string>GridHost</string>
44+
<key>Key</key>
45+
<string>preference_grid_mode_host</string>
46+
<key>DefaultValue</key>
47+
<string></string>
48+
<key>IsSecure</key>
49+
<false/>
50+
<key>KeyboardType</key>
51+
<string>URL</string>
52+
<key>AutocapitalizationType</key>
53+
<string>None</string>
54+
<key>AutocorrectionType</key>
55+
<string>No</string>
56+
</dict>
57+
<dict>
58+
<key>Type</key>
59+
<string>PSTextFieldSpecifier</string>
60+
<key>Title</key>
61+
<string>GridPort</string>
62+
<key>Key</key>
63+
<string>preference_grid_mode_port</string>
64+
<key>DefaultValue</key>
65+
<string>4444</string>
66+
<key>IsSecure</key>
67+
<false/>
68+
<key>KeyboardType</key>
69+
<string>NumberPad</string>
70+
<key>AutocapitalizationType</key>
71+
<string>None</string>
72+
<key>AutocorrectionType</key>
73+
<string>No</string>
74+
</dict>
3375
</array>
3476
</dict>
3577
</plist>

iphone/Settings.bundle/en.lproj/Root.strings

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
"Server" = "Server";
44
"Port" = "Port";
5+
"Grid" = "Grid";
6+
"GridHost" = "Host";
7+
"GridPort" = "Port";

iphone/iWebDriver.xcodeproj/project.pbxproj

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
289233AE0DB2D0DB0083E9F9 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233A90DB2D0DB0083E9F9 /* MainViewController.m */; };
2121
289233AF0DB2D0DB0083E9F9 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233AB0DB2D0DB0083E9F9 /* RootViewController.m */; };
2222
289233B00DB2D0DB0083E9F9 /* FlipsideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233AD0DB2D0DB0083E9F9 /* FlipsideViewController.m */; };
23+
40BE09AB147714580042C6DA /* Status.m in Sources */ = {isa = PBXBuildFile; fileRef = 40BE09AA147714580042C6DA /* Status.m */; };
24+
40BE09AC147715AA0042C6DA /* Status.m in Sources */ = {isa = PBXBuildFile; fileRef = 40BE09AA147714580042C6DA /* Status.m */; };
2325
64084BF312B6C6A10049D2FB /* Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = 731C4510128BBF4000261249 /* Storage.m */; };
2426
64084BF412B6C6C90049D2FB /* Database.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D14FCC1289B6540074E63B /* Database.m */; };
2527
64084BF512B6C6C90049D2FB /* GeoLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 731C450E128BBF4000261249 /* GeoLocation.m */; };
@@ -172,6 +174,8 @@
172174
289233AD0DB2D0DB0083E9F9 /* FlipsideViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FlipsideViewController.m; path = Classes/FlipsideViewController.m; sourceTree = "<group>"; };
173175
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
174176
32CA4F630368D1EE00C91783 /* iWebDriver_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iWebDriver_Prefix.pch; sourceTree = "<group>"; };
177+
40BE09A9147714580042C6DA /* Status.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Status.h; sourceTree = "<group>"; };
178+
40BE09AA147714580042C6DA /* Status.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Status.m; sourceTree = "<group>"; };
175179
642C489E112260150064EB9C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
176180
642C48A3112260480064EB9C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
177181
643822E812C0305900F0C7CC /* atoms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = atoms.h; sourceTree = "<group>"; };
@@ -466,6 +470,8 @@
466470
648EB1FC137C63B800DEFD44 /* Css.m */,
467471
731C450D128BBF4000261249 /* GeoLocation.h */,
468472
731C450E128BBF4000261249 /* GeoLocation.m */,
473+
40BE09A9147714580042C6DA /* Status.h */,
474+
40BE09AA147714580042C6DA /* Status.m */,
469475
731C450F128BBF4000261249 /* Storage.h */,
470476
731C4510128BBF4000261249 /* Storage.m */,
471477
64D8AA411120B94D001649CC /* SessionRoot.h */,
@@ -718,7 +724,7 @@
718724
);
719725
runOnlyForDeploymentPostprocessing = 0;
720726
shellPath = /bin/sh;
721-
shellScript = "if [ -e ${PROJECT_DIR}/../go ]; then\n cd ${PROJECT_DIR}/..\n echo \"Regenerating iPhone atoms header file\"\n\n HEADER=\"${PROJECT_DIR}/src/objc/atoms.h\"\n BACKUP=\"${HEADER}.orig\"\n\n if [ -e ${HEADER} ]; then\n mv ${HEADER} ${BACKUP}\n fi\n\n ./go iphone_atoms\n BUILD_RESULT=$?\n if [ $BUILD_RESULT -ne 0 ]; then\n echo \"Failed to regenerate header file; restoring original\"\n if [ -e ${BACKUP} ]; then\n mv ${BACKUP} ${HEADER}\n fi\n exit $BUILD_RESULT\n else\n if [ -e ${BACKUP} ]; then\n rm ${BACKUP}\n fi\n fi\nelse\n echo \"Unable to locate \"go\" script; using existing atoms header snapshot\"\nfi\n";
727+
shellScript = "if [ ! -e ${PROJECT_DIR}/src/objc/atoms.h ]; then\n if [ -e ${PROJECT_DIR}/../go ]; then\n cd ${PROJECT_DIR}/..\n echo \"Regenerating iPhone atoms header file\"\n\n ./go iphone_atoms\n BUILD_RESULT=$?\n if [ $BUILD_RESULT -ne 0 ]; then\n echo \"Failed to regenerate header file\"; exit $BUILD_RESULT\n fi\nelse\n echo \"Unable to locate \\\"go\\\" script;\"\nfi\nfi\n";
722728
};
723729
8399890A0EE605A30074D106 /* ShellScript */ = {
724730
isa = PBXShellScriptBuildPhase;
@@ -787,13 +793,15 @@
787793
643822F712C032F600F0C7CC /* Element.mm in Sources */,
788794
64A2262E12C1828000537E73 /* NSData+Base64.m in Sources */,
789795
648EB1FD137C63B800DEFD44 /* Css.m in Sources */,
796+
40BE09AB147714580042C6DA /* Status.m in Sources */,
790797
);
791798
runOnlyForDeploymentPostprocessing = 0;
792799
};
793800
839988DC0EE6052D0074D106 /* Sources */ = {
794801
isa = PBXSourcesBuildPhase;
795802
buildActionMask = 2147483647;
796803
files = (
804+
40BE09AC147715AA0042C6DA /* Status.m in Sources */,
797805
64BFFCBC12B6EC0D00FEB710 /* NSObject+SBJSON.m in Sources */,
798806
64BFFCBD12B6EC0D00FEB710 /* NSString+SBJSON.m in Sources */,
799807
64BFFCBE12B6EC0D00FEB710 /* SBJSON.m in Sources */,
@@ -876,7 +884,7 @@
876884
GCC_PREFIX_HEADER = src/objc/iWebDriver_Prefix.pch;
877885
HEADER_SEARCH_PATHS = "$(COCOAHTTPSERVER_HEADERS)/**";
878886
INFOPLIST_FILE = Info.plist;
879-
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
887+
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
880888
LIBRARY_SEARCH_PATHS = (
881889
"$(inherited)",
882890
"\"$(SRCROOT)/iphoneos.sdk/usr/local/lib\"",
@@ -909,7 +917,7 @@
909917
GCC_PREFIX_HEADER = src/objc/iWebDriver_Prefix.pch;
910918
HEADER_SEARCH_PATHS = "$(COCOAHTTPSERVER_HEADERS)/**";
911919
INFOPLIST_FILE = Info.plist;
912-
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
920+
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
913921
LIBRARY_SEARCH_PATHS = (
914922
"$(inherited)",
915923
"\"$(SRCROOT)/iphoneos.sdk/usr/local/lib\"",

iphone/lib/buildtime-src/cocoahttpserver/CocoaHTTPServerLibrary.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
PATCHED_CODE = "$(PROJECT_DIR)/extensions/patched";
300300
PREBINDING = NO;
301301
PRODUCT_NAME = CocoaHTTPServer;
302+
SDKROOT = iphoneos5.0;
302303
};
303304
name = Debug;
304305
};
@@ -312,6 +313,7 @@
312313
PATCHED_CODE = "$(PROJECT_DIR)/extensions/patched";
313314
PREBINDING = NO;
314315
PRODUCT_NAME = CocoaHTTPServer;
316+
SDKROOT = iphoneos5.0;
315317
ZERO_LINK = NO;
316318
};
317319
name = Release;

iphone/src/objc/HTTPServerController.m

+70-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "WebDriverHTTPConnection.h"
2222
#import "RESTServiceMapping.h"
2323
#import "WebDriverPreferences.h"
24+
#import "Status.h"
2425

2526
#import <sys/types.h>
2627
#import <sys/socket.h>
@@ -33,6 +34,8 @@ @implementation HTTPServerController
3334
@synthesize viewController = viewController_;
3435
@synthesize serviceMapping = serviceMapping_;
3536

37+
static NSMutableData *webData;
38+
3639
-(NSString *)getAddress {
3740

3841
struct ifaddrs *head;
@@ -74,6 +77,7 @@ -(id) init {
7477
if (![super init])
7578
return nil;
7679
UInt16 portNumber = [[WebDriverPreferences sharedInstance] serverPortNumber];
80+
NSString* grid = [[WebDriverPreferences sharedInstance] gridLocation];
7781

7882
server_ = [[WebDriverHTTPServer alloc] init];
7983

@@ -93,14 +97,79 @@ -(id) init {
9397
[self getAddress],
9498
[server_ port]);
9599

96-
status_ = [[NSString alloc] initWithFormat:@"Started at http://%@:%d/hub/",
100+
status_ = [[NSString alloc] initWithFormat:@"Started at http://%@:%d/wd/hub/",
97101
[self getAddress],
98102
[server_ port]];
99103

104+
if([grid length] > 0) {
105+
NSString *device;
106+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
107+
device = DEVICE_IPAD;
108+
} else {
109+
device = DEVICE_IPHONE;
110+
}
111+
NSString* gridPort = [[WebDriverPreferences sharedInstance] gridPort];
112+
113+
NSString *registerUrlStr = [NSString stringWithFormat:@"http://%@:%@/grid/register", grid, gridPort];
114+
115+
// make http request to grid host registering self as a single node with just safari to test.
116+
NSString *json = [NSString stringWithFormat:@"{'class':'org.openqa.grid.common.RegistrationRequest',"
117+
"'capabilities':[{'seleniumProtocol':'WebDriver','browserName':'%@','maxInstances':1,'platform':'MAC'}],"
118+
"'configuration':{'port':%d"
119+
",'register':True,'host':%@"
120+
",'proxy':'org.openqa.grid.selenium.proxy.DefaultRemoteProxy','maxSession':1,"
121+
"'hubHost':'%@','hubPort':'%@','role':'wd','registerCycle':5000,"
122+
"'hub':'%@','remoteHost':'http://%@:%d'"
123+
"}}", device, [server_ port], [self getAddress], grid, gridPort, registerUrlStr, [self getAddress], [server_ port] ];
124+
125+
126+
NSURL *registerUrl = [NSURL URLWithString:registerUrlStr];
127+
128+
NSMutableURLRequest *gridRegister = [NSMutableURLRequest requestWithURL:registerUrl];
129+
130+
NSString *msgLength = [NSString stringWithFormat:@"%d", [json length]];
131+
132+
[gridRegister addValue: msgLength forHTTPHeaderField:@"Content-Length"];
133+
[gridRegister setHTTPMethod:@"POST"];
134+
[gridRegister setHTTPBody: [json dataUsingEncoding:NSUTF8StringEncoding]];
135+
136+
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:gridRegister delegate:self];
137+
138+
if (theConnection) {
139+
// Create the NSMutableData to hold the received data.
140+
// receivedData is an instance variable declared elsewhere.
141+
webData = [[NSMutableData data] retain];
142+
} else {
143+
// Inform the user that the connection failed.
144+
}
145+
146+
}
147+
100148
serviceMapping_ = [[RESTServiceMapping alloc] init];
101149

102150
return self;
103151
}
152+
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
153+
{
154+
[webData setLength: 0];
155+
}
156+
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
157+
{
158+
[webData appendData:data];
159+
}
160+
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
161+
{
162+
NSLog(@"ERROR with theConenction");
163+
[connection release];
164+
[webData release];
165+
}
166+
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
167+
{
168+
NSLog(@"DONE. Received Bytes: %d", [webData length]);
169+
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
170+
NSLog(@"%@",theXML);
171+
[theXML release];
172+
}
104173

105174
// Singleton
106175

iphone/src/objc/RESTServiceMapping.m

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import "JSONRESTResource.h"
2525
#import "Session.h"
2626
#import "SessionRoot.h"
27+
#import "Status.h"
2728
#import "HTTPResponse+Utility.h"
2829
#import "RootViewController.h"
2930

@@ -45,6 +46,9 @@ - (id)init {
4546
// The root of our REST service.
4647
HTTPVirtualDirectory *restRoot = [[[HTTPVirtualDirectory alloc] init] autorelease];
4748
[serverRoot_ setResource:restRoot withName:@"hub"];
49+
50+
// Respond to /status
51+
[restRoot setResource:[[[Status alloc] init] autorelease] withName:@"status"];
4852

4953
// Make the root also accessible from /wd/hub. This will allow clients hard
5054
// coded for the java Selenium server to also work with us.
@@ -71,6 +75,7 @@ - (id)init {
7175
// Pass nil in the |query|, |method| or |data| arguments to ignore.
7276
+ (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
7377
toQuery:(NSString **)query
78+
toUri:(NSURL **)uri
7479
method:(NSString **)method
7580
data:(NSData **)data {
7681
// Extract method
@@ -81,8 +86,8 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
8186

8287
// Extract requested URI
8388
if (query != nil) {
84-
NSURL *uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
85-
*query = [uri relativeString];
89+
*uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
90+
*query = [*uri relativeString];
8691
}
8792

8893
// Extract POST data
@@ -95,11 +100,13 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
95100
- (NSObject<HTTPResponse> *)httpResponseForRequest:(CFHTTPMessageRef)request {
96101

97102
NSString *query;
103+
NSURL *uri;
98104
NSString *method;
99105
NSData *data;
100106

101107
[RESTServiceMapping propertiesOfHTTPMessage:request
102108
toQuery:&query
109+
toUri:&uri
103110
method:&method
104111
data:&data];
105112

@@ -119,10 +126,9 @@ + (void)propertiesOfHTTPMessage:(CFHTTPMessageRef)request
119126
// Unfortunately, WebDriver only supports absolute redirects (r733). We need
120127
// to expand all relative redirects to absolute redirects.
121128
if ([response isKindOfClass:[HTTPRedirectResponse class]]) {
122-
NSURL *uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request) autorelease];
123129
[(HTTPRedirectResponse *)response expandRelativeUrlWithBase:uri];
124130
}
125-
131+
126132
if (response == nil) {
127133
NSLog(@"404 - could not create response for request at %@", query);
128134
}

iphone/src/objc/Status.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Status.h
3+
// iWebDriver
4+
//
5+
// Created by Luke Inman-Semerau on 11/17/11.
6+
// Copyright (c) 2011 Free Software Conservancy. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
21+
#import <Foundation/Foundation.h>
22+
#import "HTTPVirtualDirectory.h"
23+
24+
static NSString * const DEVICE_IPHONE = @"iphone";
25+
static NSString * const DEVICE_IPAD = @"ipad";
26+
27+
@interface Status : HTTPVirtualDirectory
28+
29+
@end

0 commit comments

Comments
 (0)