<commit_before>//
//  RPSLSUITests.swift
//  RPSLSUITests
//
//  Created by <NAME> on 10/5/15.
//  Copyright © 2015 Magnet Systems, Inc. All rights reserved.
//

import XCTest

class RPSLSSignInTests: XCTestCase {
    let app = XCUIApplication()
    
    override func setUp() {
        super.setUp()
        // 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.
        app.launch()
        
        // added condition to look for notification alert and confirm
        if XCUIApplication().alerts.collectionViews.buttons["OK"].exists {
            app.alerts.collectionViews.buttons["OK"].tap()
        }

    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    // sign in
    private func signIn(user:String, password:String) {
        let usernameTextField = app.textFields["Username"]
        usernameTextField.tap()
        usernameTextField.typeText(user)
        
        let passwordSecureTextField = app.secureTextFields["Password"]
        passwordSecureTextField.tap()
        passwordSecureTextField.typeText(password)
    }
    
    // wait for element
    private func evaluateElementExist(element:AnyObject) {
        let exists = NSPredicate(format: "exists == 1")
        expectationForPredicate(exists, evaluatedWithObject: element, handler: nil)
        waitForExpectationsWithTimeout(30, handler: nil)
    }
    
    // confirm alert
    private func confirmAlert(title: String, message: String) {
        if app.alerts.collectionViews.buttons["OK"].exists {
            let title = app.staticTexts[title]
            let message = app.staticTexts[message]
            
            evaluateElementExist(title)
            evaluateElementExist(message)
            app.buttons["OK"].tap()
        }
    }
    
    // sign in and registration tests
    func test1signInNonExistingUser() {
        let signinButton = app.buttons["Sign In"]
        
        evaluateElementExist(signinButton)
        app.textFields["Username"].tap() // get app focus by tapping username if notification was confirmed
        signIn("nonexistinguser", password: "password")
        app.buttons["Sign In"].tap()
        confirmAlert("Error", message: "Not Authorized. Please check your credentials and try again.")
    }
    
    func test2registerExistingUser() {
        signIn("serveruser", password: "password")
        app.buttons["Register"].tap()
        confirmAlert("Error Registering User", message: "You have tried to create a duplicate entry.")
    }
    
    func test3registerEmptyUserName() {
        signIn("", password: "password")
        app.buttons["Register"].tap()
        confirmAlert("Error", message: "Username must be at least 5 characters in length.")
    }
    
    func test4registerEmptyPassword() {
        signIn("newuser", password: "")
        app.buttons["Register"].tap()
        confirmAlert("Error", message: "You must provide a password")
    }
    
    func test5signInEmptyUsername() {
        signIn("", password: "password")
        app.buttons["Sign In"].tap()
        confirmAlert("Error", message: "Username must be at least 5 characters in length.")
    }
    
    func test6signInEmptyPassword() {
        signIn("newuser", password: "")
        app.buttons["Sign In"].tap()
        confirmAlert("Error", message: "You must provide a password")
    }
    
    func test7registerUser() {
        let findOpponentButton = app.buttons["Find Opponent"]
        
        signIn("rpslsuser", password: "password")
        app.buttons["Register"].tap()
        evaluateElementExist(findOpponentButton)
        XCTAssertEqual(app.staticTexts["Connected as rpslsuser"].exists, true)
    }
    
    func test8signInUser() {
        let findOpponentButton = app.buttons["Find Opponent"]
        <commit_msg>modified sign in test 1 and 6 to purposely fail to verify jenkins picks up failure<commit_after>//
//  RPSLSUITests.swift
//  RPSLSUITests
//
//  Created by <NAME> on 10/5/15.
//  Copyright © 2015 Magnet Systems, Inc. All rights reserved.
//

import XCTest

class RPSLSSignInTests: XCTestCase {
    let app = XCUIApplication()
    
    override func setUp() {
        super.setUp()
        // 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.
        app.launch()
        
        // added condition to look for notification alert and confirm
        if XCUIApplication().alerts.collectionViews.buttons["OK"].exists {
            app.alerts.collectionViews.buttons["OK"].tap()
        }

    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    // sign in
    private func signIn(user:String, password:String) {
        let usernameTextField = app.textFields["Username"]
        usernameTextField.tap()
        usernameTextField.typeText(user)
        
        let passwordSecureTextField = app.secureTextFields["Password"]
        passwordSecureTextField.tap()
        passwordSecureTextField.typeText(password)
    }
    
    // wait for element
    private func evaluateElementExist(element:AnyObject) {
        let exists = NSPredicate(format: "exists == 1")
        expectationForPredicate(exists, evaluatedWithObject: element, handler: nil)
        waitForExpectationsWithTimeout(30, handler: nil)
    }
    
    // confirm alert
    private func confirmAlert(title: String, message: String) {
        if app.alerts.collectionViews.buttons["OK"].exists {
            let title = app.staticTexts[title]
            let message = app.staticTexts[message]
            
            evaluateElementExist(title)
            evaluateElementExist(message)
            app.buttons["OK"].tap()
        }
    }
    
    // sign in and registration tests
    func test1signInNonExistingUser() {
        let signinButton = app.buttons["Sign In"]
        
        evaluateElementExist(signinButton)
        app.textFields["Username"].tap() // get app focus by tapping username if notification was confirmed
        signIn("nonexistinguser", password: "password")
        app.buttons["Sign In"].tap()
        confirmAlert("Error!", message: "Not Authorized. Please check your credentials and try again.")
    }
    
    func test2registerExistingUser() {
        signIn("serveruser", password: "password")
        app.buttons["Register"].tap()
        confirmAlert("Error Registering User", message: "You have tried to create a duplicate entry.")
    }
    
    func test3registerEmptyUserName() {
        signIn("", password: "password")
        app.buttons["Register"].tap()
        confirmAlert("Error", message: "Username must be at least 5 characters in length.")
    }
    
    func test4registerEmptyPassword() {
        signIn("<PASSWORD>user", password: "")
        app.buttons["Register"].tap()
        confirmAlert("Error", message: "You must provide a password")
    }
    
    func test5signInEmptyUsername() {
        signIn("", password: "password")
        app.buttons["Sign In"].tap()
        confirmAlert("Error", message: "Username must be at least 5 characters in length.")
    }
    
    func test6signInEmptyPassword() {
        signIn("<PASSWORD>", password: "")
        app.buttons["Sign In"].tap()
        confirmAlert("Error!", message: "You must provide a password")
    }
    
    func test7registerUser() {
        let findOpponentButton = app.buttons["Find Opponent"]
        
        signIn("rpslsuser", password: "password")
        app.buttons["Register"].tap()
        evaluateElementExist(findOpponentButton)
        XCTAssertEqual(app.staticTexts["Connected as rpslsuser"].exists, true)
    }
    
    func test8signInUser() {
        let findOpponentButton = app.buttons["Find Opponent"]
        
{'fraction_non_alphanumeric': 0.10317556880399076, 'fraction_numerical': 0.005596787930405159, 'mean_word_length': 2.5584415584415585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6875625', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2172, 'n_words': 603}