1

Currently I have a form with 10 fields that I need to do sendkeys > store the value and after assert this value when save the form. For each of these fields I need to create a function and store the value in a variable or is there a better way?

My actual code:

var email = driver.findElement(By.name('email'));
email.sendKeys('info@domain.com');
email.getAttribute("value").then(function(email_text) {
    var email = email_text;
});

Cheers, Rafael

Rafael C.
  • 2,245
  • 4
  • 29
  • 45
  • you can use express sessions, save some data into session and you can access it anywhere from your project – Mario Rozic Aug 01 '16 at 21:36
  • @MarioRozic example? – Rafael C. Aug 01 '16 at 21:38
  • What's wrong with storing the value in a variable? – Noah Sussman Aug 02 '16 at 00:48
  • nothing wrong, but as I explained above I have a form with 10 fields, the above code is to store only one of them. I need to repeat this code 10 times or is there any better way to do it? – Rafael C. Aug 02 '16 at 03:25
  • For example, if my form has 10 fields, to store each sendKeys from of these fields see the code (the code is too long just to do this): https://gist.github.com/anonymous/8ad5ffbe2c2d134b1297f69e259c591a. Using python, for example, I can use just `email = driver.findElement(by_name('dog')).sendKeys('tobby');`. Using node is there any simple way to do this? – Rafael C. Aug 03 '16 at 01:49

2 Answers2

0

If I understand correct, the process looks like you should fill some fields, remember their values and check values after the form has been submitted.

There is no one standard decision for tasks like this, it depends on developer.

So, we know which values we need and can store it for example in map

{
'email':'example@email.com',
'telephone':111222333
}

Key is name for finding element, value - for sendKey and checkValue methods.

You should write two methods, which will work with test data map and will fill inputs and check values in cycle by map keys.

Sabik
  • 1,599
  • 1
  • 11
  • 10
  • For example, if my form has 10 fields, to store each sendKeys from of these fields see the code (the code is too long just to do this): https://gist.github.com/anonymous/8ad5ffbe2c2d134b1297f69e259c591a. Using python, for example, I can use just `email = driver.findElement(by_name('dog')).sendKeys('tobby');`. Using node is there any simple way to do this? – Rafael C. Aug 03 '16 at 01:48
  • You can apply decision with cycle and representation your inputs values as array of objects. It will decrease your code – Sabik Aug 03 '16 at 11:39
0

Do you mean you want to do this as an array?

// you can represent each field as an object
var fields = [
    { elementName: 'email',    expectedText: 'info@domain.com' },
    { elementName: 'password', expectedText: 'bla bla bla' }
];

// sendKeys to each field with the specified text
fields.forEach(function(field) {
    browser.driver.findElement(by.name(field.elementName)).sendKeys(field.expectedText);
});

// to get all the field text (from promises) and store it as an array
browser.controlFlow().execute(function() {
    var textArray = [];
    fields.forEach(function(field) {
        browser.driver.findElement(by.name(field.elementName)).getAttribute('value').then(function(actualText) {
            textArray.push({elementName: field.elementName, actualText: actualText});
        });
    });
    return textArray;
}).then(function(storedTextArray) {
    // do something with the stored text array here
});
martin770
  • 1,271
  • 11
  • 15
  • For example, if my form has 10 fields, to store each sendKeys from of these fields see the code (the code is too long just to do this): https://gist.github.com/anonymous/8ad5ffbe2c2d134b1297f69e259c591a. Using python, for example, I can use just `email = driver.findElement(by_name('dog')).sendKeys('tobby');`. Using node is there any simple way to do this? – Rafael C. Aug 03 '16 at 01:47