I'm writing scripts in Xcode to run some UI Tests and I wanted to use some global variables.
My first attempt was to declared a variable in @interface with type strong like so:
@interface Extended_Tests : XCTestCase
@property (strong) NSMutableArray *list;
@property (strong) NSString *name;
@end
but that didn't work.
I ended up using the old-fashioned C way of declaring the variable outside the methods.
My question is, why didn't this work? Why don't the values in the variables persist across all methods?
EDIT: My methods:
- (void)testMultiUser1 {
    [[[XCUIApplication alloc] init] launch];
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app.buttons[@"Sign-in button"] tap];
    sleep(5);
    user1 = [app.staticTexts elementBoundByIndex:0].label;
    [app.otherElements[@"LibraryView"] tap];
    sleep(5);
    _list = [[NSMutableArray alloc] init];
    for(int i = 0; i < 3; i++){
        XCUIElementQuery *file1 = [[app.cells elementBoundByIndex:i] descendantsMatchingType:XCUIElementTypeStaticText];
        NSString *number = [file1 elementBoundByIndex:0].label;
        [_list addObject:number];
    }
    XCTAssert(_list);
}
I expected this to save the variables into the array _list so I can use it in another method like this:
-(void)testMultiUser3{
    //Go into Library and make sure top 3 files are different from user1
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app.otherElements[@"LibraryView"] tap];
    sleep(5);
    NSMutableArray *user2files = [[NSMutableArray alloc] init];
    for(int i = 0; i < 3; i++){
        XCUIElementQuery *list1 = [[app.cells elementBoundByIndex:i] descendantsMatchingType:XCUIElementTypeStaticText];
        NSString *number = [list1 elementBoundByIndex:0].label;
        [user2files addObject:number];
    }
    XCTAssert(!([user2files[0] isEqualToString:_list[0]] && [user2files[1] isEqualToString:_list[1]] && [user2files[2] isEqualToString:_list[2]]));
    }
 
    