How to go about integrating Brominet into your own applications.
by Noah Sussman
It is recommended to look at JustPlayed in order to better understand how to use Ian's Encumber module.
cd MY_PROJECT
git clone git://github.com/textarcana/brominet brominet
git clone git://github.com/undees/cocoahttpserver server
git clone git://github.com/undees/asi-http-request asi-http-request
-
In XCode, duplicate your application's main target. By convention the target is named "Brominet."
-
Add a new group named
Brominet
to your project. Link theBrominet
group only with Brominet target. -
Drag the needed objective-c files from
MY_PROJECT/brominet
(in the Finder), into theBrominet
group. Use the list below as a guide as to which files are needed. Or just put Ian's project side by side with yours, and then make sure to copy over the same files. (list of which files TK). Make sure the path for all the files is "relative to project." -
Add a new
CocoaHTTPServer
group. Link theCocoaHTTPServer
group, only with the Brominet target. -
Drag the needed objective-c files from
MY_PROJECT/server
, into theCocoaHTTPServer
group. -
Add a new
ASIHTTPRequest
group. Link theASIHTTPRequest
group, only with the Brominet target. -
Drag the needed objective-c files from
MY_PROJECT/server
, into theASIHTTPRequest
group.
Do a "Get Info" on the brominet Brominet target, and in Build section, do the following:
-
add this to the Header Search Path:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/libxml2;
-
link the libxml2 library to your Frameworks folder
-
add the preprocessor macro (GCC_PREPROCESSOR_DEFINITIONS) with value BROMINET_ENABLED;
-
make sure GCC_C_LANGUAGE_STANDARD is c99 or gnu99
Now update the app delegate with some ifdefs. The easiest way to see which files are required, may be to look at the app delegate in Ian Dees' JustPlayed example app,.
At a minimum, do the following.
-
add the ifdefs HTTP server include, and invocation to
AppDelegate.h
-
add the ifdef for headers to
AppDelegate.m
-
add the ifdef to launch the server to
AppDelegate.m
-
add the ifdef stop the server and garbage collect, to
AppDelegate.m
Because Brominet is integrated with your app, it's important to be aware of all the dependencies for both Brominet and your own code.
Note that in Ian's JustPlayed example, ASIHTTPRequest uses the Reachability 1.5 API. Apple has since upgraded the Reachability library to 2.0, and ASIHTTPRequest now supports both versions of the Reachability API. Although the new version is backward compatible, be aware that newer applications may already be including Reachability 2.0.
First, to see Brominet in action, take a look at the Cucumber functional tests for iPhone that Ian Dees presented at OSCON 2009.
If you just want to test drive Brominet, you can follow the instructions in my fork.
I'm using my fork of the JustPlayed example application as an example. The procedure outline here is the same for any app into which you've installed Brominet.
If you build and start the simulator with
my fork of the JustPlayed example application,
then you should notice a new service running on port 50000. You can
then control the app in the simulator, by sending chunks of XML over
HTTP. This is all handled by Ian's encumber.rb
library.
If you build the Brominet-enabled app onto an iPhone, then you can control the iPhone over a wi-fi network.
To find your iPhone's IP address, follow these instructions.
-
Assuming you are already connected to a wi-fi network, go to Settings > Wi-Fi.
-
Tap the name of the network to which you are currently connected (the one with a check mark next to it).
-
In the DHCP tab, note the IP address of your device.
-
Assuming your computer is connected to the same wi-fi network, you can now connect to the Brominet Web service on your iPhone, on port
Here is how to use the IRB to call the app directly and dump the XML of the GUI. Type or paste the following 3 commands into the IRB.
load 'lib/encumber.rb'
@gui = Encumber::GUI.new 'localhost'
File.open('encumber_gui.xml', 'w') {|f| f.write(@gui.dump) }
Then open encumber_gui.xml
in an XML editor like Firefox or XML
Spy. Once you work out which XPaths correspond to the buttons in your
app, you can start tapping buttons using Encumber::GUI#press
@gui.press '//xpath/to/button'
If you have deployed a Brominet-enabled app on an iPhone, then you can use the same procedure to connect to it.
@gui = Encumber::GUI.new '10.0.1.23'
Finally, if you start the the
IRB
in the root of my fork of JustPlayed, then you can use the convenience
methods that are implemented in
my .irbc
file.