Starter Step

UIScript

Posted on: August 9, 2009

I have just added simple scripting support to UISpec. It allows you to send a String as a script and have it run dynamically. This really opens up the possibility of using UISpec with other languages like Ruby, Java, etc. The following is taken from the documentation found here.

UIScript’s goal is to provide a simple lightweight scripting language that supports all the functionality of UISpec, but without having to write Objective-C code. Instead you write UIScript which is very similar to Smalltalk.

Currently UIScript only supports straight messages, which means there is no support for things like variables and loops or decisions (for, while, if else, etc…). And right now UISpec recognizes only Strings, Integers, and BOOLs.

You can run a script in your test by calling the C function:

UIQuery * $(NSString *script, …);

Messages

Like in Objective-C, UIScript is based on sending messages to objects. The only real difference in writing UIScript vs Objective-C is that you take out all the dot notation and brackets.

$(@”navigationButton touch”);
$(@”tableView tableViewCell all should not be selected”);

As you can see it’s very similar to what you are used to writing, except without all the syntactic sugar, making the script even more readable.

Strings

Strings in UISpec are just quoted values like ‘Hello’ or ‘Good Bye’, and there is no need to use the @ symbol as a prefix like you do in Objective-C.

$(@”navigationButton label text:’Save’ touch”);

$(@”textField placeholder:’Username’ setText:’bkuser'”);
//If you need to include a String dynamically just use NSString formatting
$(@”textField placeholder:’Username’ setText:’%@'”, [Config userName]);

Integers

Currently Integers are the only number support in UIScript. We hope to have support for decimals very soon.

$(@”tableView should have numberOfSections:3″);

$(@”label text:’Returns’ parent tableViewCell should have accessoryType:3″);
//Or you can use NSString formatting
$(@”label text:’Returns’ parent tableViewCell should have accessoryType:%d”, UITableViewCellAccessoryCheckmark);

BOOLs

The BOOLs YES and NO are also supported in UIScript.

$(@”tableView tableViewCell first should have isSelected:YES”);
$(@”tableView tableViewCell last should have isSelected:NO”);

//Or you can use NSString formatting
int rows = $(@”tableView numberOfRowsInSection:0″);
$(@”tableView should have:%@”, rows==3);

Example

Here is the itShouldUpdateUserRoles example from the demo rewritten using UIScript

-(void)itShouldUpdateUserRoles {
[self addTestUser];

$(@”label with text:’Brian Knorr’ touch”);
$(@”label text:’User Roles’ touch”);

$(@”tableView scrollToBottom”);
$(@”label text:’Returns’ touch”);
$(@”label text:’Returns’ parent tableViewCell should be selected”);
$(@”label text:’Returns’ parent tableViewCell should have accessoryType:%d”, UITableViewCellAccessoryCheckmark);

$(@”label text:’Returns’ touch”);
$(@”label text:’Returns’ parent tableViewCell should have accessoryType:%d”, UITableViewCellAccessoryNone);

$(@”view:’UINavigationItemButtonView’ touch”);
$(@”view:’UINavigationItemButtonView’ touch”);

[self deleteTestUser];
}

Advertisements

6 Responses to "UIScript"

Please tell me how to automate the UIWebView instances using UISpec.

I am haivng a uiwebview and i am loading an html page. I want to automate the action of clicking a button in that page.

Is there anyway i can automate that like native controls??

I can access the webview using app.webview, but how i will simulate the button taps?

I haven’t tried this myself, but you can always send javascript to the UIWebView with the method:

stringByEvaluatingJavaScriptFromString:

So in UISpec it might look something like:

[app.webView stringByEvaluatingJavaScriptFromString:@”$(‘#button’).click();”];

HI, I cant figure out how to switch among items in tabbar. Can you please help me? Thanx

Hello,

I am trying to use UIScript with Frank but can’t understand what I should write for the script query.

For Example:
I write :
Then /^I should see an element of class “([^\”]*)” with name “([^\”]*)”$/ do |className, classLabel|
check_element_exists(“view marked:’#{classLabel}’ parent view:’#{className}'”)
end

and call it like:
Then I should see an element of class “PDColoredProgressView” with name “Progress”

and test fails although i have a {“label”:”Progress”,”class”:”PDColoredProgressView”}, seen on http://localhost:37265/inspect

I think I need a starting point to understand UIScript and Frank infrastructure. I looked UIQuery.m under uispec>dsl and didn’t understand UIQuery * $(NSMutableString *script, …); notation and following messages there. Where do you suggest to look for to understand the structure of Frank and UISpec?

Thanks in advance.

Hi,
I want to automate the UISwitch Button using UISpec.
Please Reply.

Thanks,
Sonal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


  • Dave: I can tell you're a ruby guy because you forgot the 'return' keyword. Thanks for the tip though!
  • Chandrashekhar H M: Hi, Thanks its working fine in iOS 6 but not in iOS 7.0. Any Suggestion on this.
  • Coeur: To change a rootViewController, without all this TVNavigationController : myNewRoot = [[UIViewController alloc] init]; myNavigationController.view
%d bloggers like this: