<commit_before>require("chromedriver");
import seleniumWebdriver = require("selenium-webdriver");
import Cucumber = require("cucumber");
import Fs = require("fs");
import Speakeasy = require("speakeasy");
import Assert = require("assert");
import Request = require("request-promise");
import BluebirdPromise = require("bluebird");

function CustomWorld() {
  const that = this;
  this.driver = new seleniumWebdriver.Builder()
    .forBrowser("chrome")
    .build();

  this.totpSecrets = {};
  this.configuration = {};

  this.visit = function (link: string) {
    return this.driver.get(link);
  };

  this.setFieldTo = function (fieldName: string, content: string) {
    return this.driver.findElement(seleniumWebdriver.By.id(fieldName))
      .sendKeys(content);
  };

  this.clearField = function (fieldName: string) {
    return this.driver.findElement(seleniumWebdriver.By.id(fieldName)).clear();
  };

  this.getErrorPage = function (code: number) {
    const that = this;
    return this.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.tagName("h1")), 2000)
      .then(function () {
        return that.driver
          .findElement(seleniumWebdriver.By.tagName("h1")).getText();
      })
      .then(function (txt: string) {
        Assert.equal(txt, "Error " + code);
      });
  };

  this.clickOnButton = function (buttonText: string) {
    const that = this;
    return this.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.tagName("button")), 2000)
      .then(function () {
        return that.driver
          .findElement(seleniumWebdriver.By.tagName("button"))
          .findElement(seleniumWebdriver.By.xpath("//button[contains(.,'" + buttonText + "')]"))
          .click();
      })
      .then(function () {
        return that.driver.sleep(1000);
      });
  };

  this.waitUntilUrlContains = function(url: string) {
    return this.driver.wait(seleniumWebdriver.until.urlIs(url), 15000);
  };

  this.loginWithUserPassword = function (username: string, password: string) {
    return that.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.id("username")), 4000)
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.id("username"))
          .sendKeys(username);
      })
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.id("password"))
          .sendKeys(password);
      })
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.tagName("button"))
          .click();
      });
  };

  this.retrieveLatestMail = function () {
    return Request({
      method: "GET",
      uri: "http://localhost:8085/messages",
      json: true
    })<commit_msg>Display current URL when redirection step fails in integration tests<commit_after>require("chromedriver");
import seleniumWebdriver = require("selenium-webdriver");
import Cucumber = require("cucumber");
import Fs = require("fs");
import Speakeasy = require("speakeasy");
import Assert = require("assert");
import Request = require("request-promise");
import BluebirdPromise = require("bluebird");

function CustomWorld() {
  const that = this;
  this.driver = new seleniumWebdriver.Builder()
    .forBrowser("chrome")
    .build();

  this.totpSecrets = {};
  this.configuration = {};

  this.visit = function (link: string) {
    return this.driver.get(link);
  };

  this.setFieldTo = function (fieldName: string, content: string) {
    return this.driver.findElement(seleniumWebdriver.By.id(fieldName))
      .sendKeys(content);
  };

  this.clearField = function (fieldName: string) {
    return this.driver.findElement(seleniumWebdriver.By.id(fieldName)).clear();
  };

  this.getErrorPage = function (code: number) {
    const that = this;
    return this.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.tagName("h1")), 2000)
      .then(function () {
        return that.driver
          .findElement(seleniumWebdriver.By.tagName("h1")).getText();
      })
      .then(function (txt: string) {
        Assert.equal(txt, "Error " + code);
      });
  };

  this.clickOnButton = function (buttonText: string) {
    const that = this;
    return this.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.tagName("button")), 2000)
      .then(function () {
        return that.driver
          .findElement(seleniumWebdriver.By.tagName("button"))
          .findElement(seleniumWebdriver.By.xpath("//button[contains(.,'" + buttonText + "')]"))
          .click();
      })
      .then(function () {
        return that.driver.sleep(1000);
      });
  };

  this.waitUntilUrlContains = function(url: string) {
    const that = this;
    return this.driver.wait(seleniumWebdriver.until.urlIs(url), 15000)
    .then(function() {}, function(err: Error) {
      that.driver.getCurrentUrl()
      .then(function(current: string) {
        console.error("====> Error due to: %s (current) != %s (expected)", current, url);
      });
      return BluebirdPromise.reject(err);
    });
  };

  this.loginWithUserPassword = function (username: string, password: string) {
    return that.driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.id("username")), 4000)
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.id("username"))
          .sendKeys(username);
      })
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.id("password"))
          .sendKeys(password);
      })
      .then(function () {
        return that.driver.findElement(seleniumWebdriver.By.tagName("button"))
          .click();
      });
  };

  this.retrieveLatestMail = function () {
    return Request({
      method: "GET",
      uri: "http://localhost:8085/messages",
      json: true
    })
{'fraction_non_alphanumeric': 0.14997431946584489, 'fraction_numerical': 0.009244992295839754, 'mean_word_length': 3.366218236173393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6487820', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1734, 'n_words': 294}