<commit_before>/**
 * @file
 * Script to test login functionnalities.
 *
 * @author <NAME> (<EMAIL>)
 */




/**
 * Initialise the variables
 */
if (!casper.cli.has("uri")) {
  casper
    .log('You must specify a base URL to run the tests.', 'error')
    .exit()
}

var uri = casper.cli.get("uri") + '/login'


/**
 * Test the login page.
 */
casper.test.begin('AW login', function suite(test) {
  casper.start(uri, function() {
    // Checking login form.
    casper.echo('Checking login form.', 'INFO')
    test_field_present(test, 'username', 'text')
    test_field_present(test, 'password', 'password')
    test_field_present(test, 'submit', 'submit')

    // Attempting login without credentials.
    casper.echo('Attempting login without credentials.', 'INFO')
    this.click('input[type="submit"]')
  });

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'username')
    test_field_error(test, 'password')

    // Attempting login without password.
    casper.echo('Attempting login without password.', 'INFO')
    this.fill('form#login-form', {
      'signin_username': 'admin',
    }, true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login without username.
    casper.echo('Attempting login without username.', 'INFO')
    this.fill('form#login-form', {
      'signin_password': '<PASSWORD>',
    }, true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'username')

    // Attempting login with unknown username.
    casper.echo('Attempting login with unknown username.', 'INFO')
    this.fill('form#login-form', {
      'signin_username': 'i_am_casper',
      'signin_password': '<PASSWORD>',
    }, true)
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login with known username but bad password.
    casper.echo('Attempting login with known username but bad password.', 'INFO')
    this.fill('form#login-form', {
      'signin_username': 'admin',
      'signin_password': '<PASSWORD>',
    }, true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login with correct credentials.
    casper.echo('Attempting login with correct credentials.', 'INFO')
    this.fill('form#login-form', {
      'signin_username': 'admin',
      'signin_password': '<PASSWORD>',
    }, true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    test.assertExists('a#logout-button', "log in successful: logout button was found")
  })<commit_msg>added a user object to simulate different users<commit_after>/**
 * @file
 * Script to test login functionnalities.
 *
 * @author <NAME> (<EMAIL>)
 */


/**
 * Initialise the variables
 */
if (!casper.cli.has("uri")) {
  casper
    .log('You must specify a base URL to run the tests.', 'error')
    .exit()
}

var uri = casper.cli.get("uri") + '/login'


/**
 * Initialise user object
 */
function User(username, password) {
    this.username = username
    this.password = password

    this.fill_login = function() {
      return {
        'signin_username': this.username,
        'signin_password': this.password,
      }
    }
}

/**
 * Test the login page.
 */
casper.test.begin('AW login', function suite(test) {
  casper.start(uri, function() {
    // Checking login form.
    casper.echo('Checking login form.', 'INFO')
    test_field_present(test, 'username', 'text')
    test_field_present(test, 'password', 'password')
    test_field_present(test, 'submit', 'submit')

    // Attempting login without credentials.
    casper.echo('Attempting login without credentials.', 'INFO')
    this.click('input[type="submit"]')
  });

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'username')
    test_field_error(test, 'password')

    // Attempting login without password.
    casper.echo('Attempting login without password.', 'INFO')
    var user = new User('admin', '')
    this.fill('form#login-form', user.fill_login(), true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login without username.
    casper.echo('Attempting login without username.', 'INFO')
    var user = new User('', 'password')
    this.fill('form#login-form', user.fill_login(), true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'username')

    // Attempting login with unknown username.
    casper.echo('Attempting login with unknown username.', 'INFO')
    var user = new User('i_am_casper_username', '<PASSWORD>')
    this.fill('form#login-form', user.fill_login(), true)
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login with known username but bad password.
    casper.echo('Attempting login with known username but bad password.', 'INFO')
    var user = new User('admin', '<PASSWORD>')
    this.fill('form#login-form', user.fill_login(), true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    // test errors
    test_url_is_login(test)
    test_field_error(test, 'password')

    // Attempting login with correct credentials.
    casper.echo('Attempting login with correct credentials.', 'INFO')
    var user = new User('admin', 'admin')
    this.fill('form#login-form', user.fill_login(), true)
    this.click('input[type="submit"]')
  })

  casper.then(function() {
    test.assertExists('a#logout-button', "log in successful: logout button was found")
  })
{'fraction_non_alphanumeric': 0.15658244680851063, 'fraction_numerical': 0.0, 'mean_word_length': 3.4769345238095237, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '98716', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1887, 'n_words': 429}