Is it possible to compare a value to a secure credential?

I’m trying to compare the value of the input field to a secure credential.

  • Are there other ways to get an input field’s value?

I’m using the getAttribute(“value”) method.
However it always returns an error every time I compare it with a secure credential

.then(() =>{
        return $browser.findElement(By.xpath("//input[contains(@utid,'phone_number_textbox')]"))
        .then((el) => {
            return el.getAttribute('value')
            .then((value) => {
                assert.equal(value,$secure.KEY_HERE, "Doesnt match");
                console.log("MATCH");
            })
        })
    })

Is it possible to compare a value to a secure.credential?

Hi, @Rose_Ann_Dela_Paz: This script works for me:

var assert = require('assert');

$browser.get('http://example.com')
  .then(function() {
    var value = 'learn@newrelicuniversity.com'
    assert.equal(value, $secure.NRU_TRAINING_EMAIL, 'Doesn\'t match');
  });

So it is possible. You might make sure that your secure credential and your input field’s value are indeed equal.

Hello @philweber , how about comparing the value on the input field by using the getAttribute(“value”) and secure credential??

Yes, this also works:

const By = $driver.By;
const assert = require('assert');

$browser.get('https://login.newrelic.com/login')
  .then(function() {
    // Put some text in the input
    return $browser.findElement(By.id('login_email')).sendKeys($secure.NRU_TRAINING_EMAIL);
  })
  .then(function() {
    // Now find the input...
    return $browser.findElement(By.id('login_email'));
  })
  .then(function(element) {
    // ...get the text...
    return element.getAttribute('value');
  })
  .then(function(value) {
    // ...and compare to the secure credential
    assert.equal(value, $secure.NRU_TRAINING_EMAIL, 'Doesn\'t match');
  });
3 Likes