Change selection parameters in forEach loop

I have the following test code:

ID = {
   CreatedBy: { id: 'createdBy' },
   ModifiedBy: { id: 'modifiedBy' }
}

Profile = {
   All: { text: 'All', val: 0 },
   Sys: { text: 'system_system@system.com', val: 1 },
   Test: { text: 'test_user@live.com', val: 2 }
}

changeSelect(dataId: EnumElement[], params: UserEnum[]) {
   dataId.forEach((data) => {
      params.forEach((elem) => {
         var label = data.id+ ' - Check option changed to - ' + elem.text;
         it(label, () => {
               return element(by.xpath('//select[@id="' + data.id + '"]/option[@value = "' + elem.val + '"]')).click();
         });
    });
}

      

In my test, I call the changeSelect () function with parameters like this:

changeSelect([ID.CreatedBy, ID.ModifiedBy], [Profile.Sys, Profile.Test]);

      

As expected, my changeSelect () function will output:

createdBy - Check option changed to - system_system@system.com
createdBy - Check option changed to - test_user@live.com
modifiedBy - Check option changed to - system_system@system.com
modifiedBy - Check option changed to - test_user@live.com

      

But this is not the result I want. How can I customize my loop to achieve the result below?

createdBy - Check option changed to - system_system@system.com
modifiedBy - Check option changed to - test_user@live.com

      

+3


source to share


1 answer


Why not use an easy one for?



changeSelect(dataId, params) {
    for(i = 0; i < dataId.length; i++){
        var data = dataId[i];
        var elem = params[i];
        var label = data.id + ' - Check option changed to - ' + elem.text;
        it(label, () => {
            return element(by.xpath('//select[@id="' + data.id + '"]/option[@value = "' + elem.val + '"]')).click();
        }
    }
}

      

0


source







All Articles