Wednesday, August 8, 2012

NSString Examples

NSLog


NSLog( @"The sky is %@.", @"blue" );
The preceding line of code results in this output:
The sky is blue.

Finding the Length of an NSString


NSString *string = @"A string to measure";
NSUInteger stringLength = [string length];
NSLog( @"The length is: %d.", stringLength);
results in:
The length is: 19.

Obtaining an Uppercase NSString


NSString *string1 = @"Make me taller.";
NSString *string2 = [string1 uppercaseString];
NSLog( @"Uppercased string: %@", string2 );

results in:
Uppercased string: MAKE ME TALLER.

Appending an NSString to Another NSString


NSString *string1 = @"The First Part ";
NSString *string2 = @"The Second Part";
NSString *result = [string1 stringByAppendingString: string2];
NSLog( @"Resulting string: %@", result );
results in:
Resulting string: The First Part The Second Part


Breaking a Sentence into Individual Word


NSString *string1 = @"This sentence is falling apart";
NSArray *words =
[string1 componentsSeparatedByCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSLog( @"Word array: %@", words);
results in:
Word array: (
This,
sentence,
is,
falling,
apart
)

C String to NSString and Back


char* cString = "Hello Universe";
NSString* nsString = [NSString stringWithUTF8String: cString];
This code does the reverse:
NSString* nsString = @"Anybody Home?";
char* cString = [nsString UTF8String];







Monday, August 6, 2012

NSString Class Reference

Here is the link for Objective C NSString Class Reference

NSString Class Reference 

Wednesday, August 1, 2012

Sunday, July 29, 2012

iOS UI Automation Test -- Select image when using carema

When we doing a UI Automation Test in iPhone Simulation, and we would like to test the camera function.

At this point, the way is to store the image which we want to scan to iphone simulation photo library , and then pop up the image library when use camera simulation.


In the simulator, it said "Tap and hold with two fingers to select image", here is the code to do that

targt.tapWithOptions({x:0.27,y:0.45},{touchCount:2, tapCount:1,duration;1.5});


this code will pop up the photo library.




And here is the UIAElement Class Reference from Apple 


UIAElement Class Reference Link

Monday, July 23, 2012

iPhone UIAutomation Javascript -- Alert View Message

To write UIAutomation Javascript,  one hard part is to handle Alert view,

Here is the example to get Alert view's title and message:

Code:

UIATarget.onAlert = function onAlert(alert){
// To get alert title
var title = alert.name();
//To get alert body message
// [0]  is title
var message = alert.staticTexts()[1].name();

              //if(message == "Are you sure to logout?")
              if(title == "Logout")
                {
                 alert.buttons()["Yes"].tap();
                 return true;
                 }
                 return false;
              }

Thursday, July 19, 2012

iOS -- Device Capabbilities

Accessing Basic Device Information


UIDevice *device = [UIDevice currentDevice];
NSLog(@"System name: %@", device.systemName);
NSLog(@"Model: %@", device.model);
NSLog(@"Name: %@", device.name);


Working with Basic Orientation



 UIDeviceOrientationUnknown—The orientation is currently unknown.
 UIDeviceOrientationPortrait—The home button is down.
 UIDeviceOrientationPortraitUpsideDown—The home button is up.
 UIDeviceOrientationLandscapeLeft—The home button is to the right.
 UIDeviceOrientationLandscapeRight—The home button is to the left.
 UIDeviceOrientationFaceUp—The screen is face up.
 UIDeviceOrientationFaceDown—The screen is face down.

Wednesday, July 4, 2012

Automating User Interface Testing with Instruments


This is a very good article for iOS UI Automating test.

This is the link.


Another good article

This is the link