         // In UI tests it is usually best to stop immediately when a failure occurs.
         continueAfterFailure = false
         // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
-        XCUIApplication().launch()
+        app.launch()
+        sleep(3)
 
         // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
     }
     
     override func tearDown() {
         // Put teardown code here. This method is called after the invocation of each test method in the class.
+        app.terminate()
         super.tearDown()
     }
     
     func testDoneButtonDisabledOnStartup() {
-        let app = XCUIApplication()
         app.buttons["Image picker"].tap()
         XCTAssert(app.navigationBars.buttons["Done"].enabled == false)
     }
     
     func testDoneButtonEnabledAfterSelection() {
-        let app = XCUIApplication()
         app.buttons["Image picker"].tap()
         app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.tap()
         XCTAssert(app.navigationBars.buttons["Done (1)"].enabled == true)
     }
     
     func testDoneButtonDisabledAfterDeselection() {
-        let app = XCUIApplication()
         app.buttons["Image picker"].tap()
         app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.tap()
         app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.tap()

    
    func testLongpressPreview() {
        
        let app = XCUIApplication()
        app.buttons["Image picker"].tap()
        app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.pressForDuration(1.0);
        app.navigationBars.buttons["Back"].tap()


class BSImagePicker_UI_Tests: XCTestCase {
        
    let app = XCUIApplication()

    override func setUp() {
        super.setUp()
        
