Commit 7c779099 authored by Alex Moore's avatar Alex Moore
Browse files

Jakes RTI Test

parent aa089a59
//
// ViewController.h
// headlessbrower_test1
//
// Created by PLUC SeniorDesign on 2/23/15.
// Copyright (c) 2015 PLUC SeniorDesign. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *test_view;
@end
//
// ViewController.m
// headlessbrower_test1
//
// Created by PLUC SeniorDesign on 2/23/15.
// Copyright (c) 2015 PLUC SeniorDesign. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// [self.test_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.xkcd.com"]]];
[self.test_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"file:///Users/plucseniordesign/Desktop/RTISetup.html"]]];
//NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
//[rq setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18" forHTTPHeaderField:@"User-Agent"];
//[self.test_view loadRequest:rq];
[self.test_view setDelegate:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[webView stringByEvaluatingJavaScriptFromString:@"var test1 = 'Hello Pluto'"];
NSString *newHtml = [webView stringByEvaluatingJavaScriptFromString:@"test1"];
NSLog(@"%@\n", newHtml);
NSString *path = [[NSBundle mainBundle] pathForResource:@"WhatPage" ofType:@"js"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSString *page = [webView stringByEvaluatingJavaScriptFromString:content];
NSLog(@"PAGE NUMBER IS: %@\n", page);
if ([page isEqual: @"0"]) { // Login Page
// Do not have login function just yet
}
else if ([page isEqual: @"1"]) {// Setup Page
// Get collections available - Testing GetAvailableCollections
NSString *getAvailablePath = [[NSBundle mainBundle] pathForResource:@"GetAvailableCollections" ofType:@"js"];
NSString *getAvailable = [NSString stringWithContentsOfFile:getAvailablePath encoding:NSUTF8StringEncoding error:nil];
NSString *available = [webView stringByEvaluatingJavaScriptFromString:getAvailable];
//NSLog(@"%@\n", available);
// Add two collections - Testing AddCollection
NSString *addSelectedPath = [[NSBundle mainBundle] pathForResource:@"AddCollection" ofType:@"js"];
NSString *addSelected = [NSString stringWithContentsOfFile:addSelectedPath encoding:NSUTF8StringEncoding error:nil];
NSString *selected = [webView stringByEvaluatingJavaScriptFromString:@"var selectedAdd = 1;"];
NSString *add = [webView stringByEvaluatingJavaScriptFromString:addSelected];
if ([add isEqual:@"-1"]) {
NSLog(@"FAILED\n");
}
else {
NSLog(@"NOT FAILED\n");
}
selected = [webView stringByEvaluatingJavaScriptFromString:@"var selectedAdd = 2;"];
add = [webView stringByEvaluatingJavaScriptFromString:addSelected];
// Get all of the collections selected - Testing GetSelectedCollections
NSString *getSelectedPath = [[NSBundle mainBundle] pathForResource:@"GetSelectedCollections" ofType:@"js"];
NSString *getSelected = [NSString stringWithContentsOfFile:getSelectedPath encoding:NSUTF8StringEncoding error:nil];
NSString *currentSelected = [webView stringByEvaluatingJavaScriptFromString:getSelected];
NSLog(@"%@\n", currentSelected);
// Remove one collection selected - Testing RemoveCollection
NSString *removeSelectedPath = [[NSBundle mainBundle] pathForResource:@"RemoveCollection" ofType:@"js"];
NSString *removeSelected = [NSString stringWithContentsOfFile:removeSelectedPath encoding:NSUTF8StringEncoding error:nil];
NSString *selectedRemove = [webView stringByEvaluatingJavaScriptFromString:@"var selectedRemove = 1;"];
NSString *remove = [webView stringByEvaluatingJavaScriptFromString:removeSelected];
// Save setup configuration - Testing SaveSetup
NSString *saveSetupPath = [[NSBundle mainBundle] pathForResource:@"SaveSetup" ofType:@"js"];
NSString *saveSetup = [NSString stringWithContentsOfFile:saveSetupPath encoding:NSUTF8StringEncoding error:nil];
NSString *save = [webView stringByEvaluatingJavaScriptFromString:saveSetup];
}
else if ([page isEqual: @"2"]) { // Scan Page
// Scan in an input (arbitrary string of "1234567") - Testing ScanBarcode
NSString *scanPath = [[NSBundle mainBundle] pathForResource:@"ScanBarcode" ofType:@"js"];
NSString *scan = [NSString stringWithContentsOfFile:scanPath encoding:NSUTF8StringEncoding error:nil];
NSString *code = [webView stringByEvaluatingJavaScriptFromString:@"var code = '1234567';"];
NSString *scaned = [webView stringByEvaluatingJavaScriptFromString:scan];
// Get scanned codes - Testing GetScanned
NSString *getScanPath = [[NSBundle mainBundle] pathForResource:@"GetScanned" ofType:@"js"];
NSString *getScan = [NSString stringWithContentsOfFile:getScanPath encoding:NSUTF8StringEncoding error:nil];
NSString *scanned = [webView stringByEvaluatingJavaScriptFromString:getScan];
NSLog(@"Scanned codes: %@\n", scanned);
// Test FinishScan
NSString *finishPath = [[NSBundle mainBundle] pathForResource:@"FinishScan" ofType:@"js"];
NSString *finish = [NSString stringWithContentsOfFile:finishPath encoding:NSUTF8StringEncoding error:nil];
NSString *isFinished = [webView stringByEvaluatingJavaScriptFromString:finish];
if ([isFinished isEqual:@"-1"])
{}
else {
NSLog(@"FINISHED NOT FAILED\n");
}
}
else if([page isEqual: @"3"]) { // Error/Action Page
// Get the error - Testing GetError
NSString *getErrorPath = [[NSBundle mainBundle] pathForResource:@"GetError" ofType:@"js"];
NSString *getError = [NSString stringWithContentsOfFile:getErrorPath encoding:NSUTF8StringEncoding error:nil];
NSString *error = [webView stringByEvaluatingJavaScriptFromString:getError];
NSLog(@"Error is %@\n", error);
// Continue - Testing GoToScan
NSString *goToScanPath = [[NSBundle mainBundle] pathForResource:@"GoToScan" ofType:@"js"];
NSString *goToScan = [NSString stringWithContentsOfFile:goToScanPath encoding:NSUTF8StringEncoding error:nil];
NSString *toScan = [webView stringByEvaluatingJavaScriptFromString:goToScan];
}
}
@end
(function() {
var url = document.URL;
if (url.search("Login") != -1)
return 0;
else if (url.search("Setup") != -1)
return 1;
else if (url.search("Scan") != -1)
return 2;
else if (url.search("Action") != -1)
return 3;
else
return 4;
})();
\ No newline at end of file
//
// main.m
// headlessbrower_test1
//
// Created by PLUC SeniorDesign on 2/23/15.
// Copyright (c) 2015 PLUC SeniorDesign. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>PLUC.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// headlessbrower_test1Tests.m
// headlessbrower_test1Tests
//
// Created by PLUC SeniorDesign on 2/23/15.
// Copyright (c) 2015 PLUC SeniorDesign. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@interface headlessbrower_test1Tests : XCTestCase
@end
@implementation headlessbrower_test1Tests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
@end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment