protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Possibility for parameterized/data driven test with protractor

Open emyphan opened this issue 12 years ago • 11 comments

Hi, for tests which are only different from data, is it possible to parameterize the test like table in cucumber or unit test? If not yet, it could be a nice feature. Thanks

emyphan avatar Mar 19 '14 10:03 emyphan

Hi,

i am trying to use ya-csv module of nodejs but not sure how to get data stored in protractor test variable?

var csv = require('ya-csv'); var col1; var reader = csv.createCsvFileReader('data.csv', { columnsFromHeader: true }); reader.addListener('data', function(data) {

col1=sys.puts(data.col1);   ???????????????

});

smtripathi99 avatar Mar 21 '14 07:03 smtripathi99

I agree. Would love to have this feature. Personally, I don't think any test framework is compete before they have facility for data driven tests!

RaviH avatar Apr 30 '14 15:04 RaviH

I hope progress on this is going well, data driven tests are a must in my opinion. I have a scenario where I need to run a test template for eleven different languages and this would really help!

magicode118 avatar Oct 03 '14 10:10 magicode118

For anyone still stuck on this, I wrote a mini tutorial on how to do it in your code in stackoverflow: http://stackoverflow.com/questions/27872783/how-do-i-open-multiple-windows-or-operate-multiple-instances/27874090#27874090

While this still requires some effort on your end and I've pointed out some shortcomings, it should allow you to write parametrized tests with protractor before there is a good solution for this.

hankduan avatar Jan 21 '15 19:01 hankduan

I created a simplified version of my spec. I would like to run "it" blocks in loop. I could use some of that value of element.all.count() in loop? thx, I tried a lot

'use strict';

describe('loopTest', function() {

    var count;
    var executionCounter = 0;

    beforeAll(function() {
        console.log('loopTest beforeAll begin', executionCounter++);
        browser.get(''); //baseUrl set in protractor.conf.js
        element
            .all(by.css('.row .btn.btn-link.btn-flat'))
            .count()
            .then(function(c) {
                count = c;
                console.log('loopTest beforeAll element.all.then', executionCounter++);
            });
    });

    var its = function() {
        console.log('its function begin', executionCounter++);
        it('it first', function() {
            expect(true).toEqual(true);
        });
        it('it second', function() {
            expect(true).toEqual(true);
        });
    };

    //protractor(jasmine) answere: No specs found, because this loop run, before beforeAll run
    //for (var int = 0; int < count; int++) {
    //with fixed constant value worked, but I want to use element.all.count() value
    for (var int = 0; int < 2; int++) {
        console.log('for loop', executionCounter++);
        its();
    }
});
[chrome #2] Using the selenium server at http://localhost:4444/wd/hub
[chrome #2] for loop 0
[chrome #2] its function begin 1
[chrome #2] for loop 2
[chrome #2] its function begin 3
[chrome #2] Started
[chrome #2] loopTest
[chrome #2] loopTest beforeAll begin 4
[chrome #2] loopTest beforeAll element.all.then 5
[chrome #2]   it first 0 ...
[chrome #2]  Passed
[chrome #2] .  it second 0 ...
[chrome #2]  Passed
[chrome #2] .  it first 1 ...
[chrome #2]  Passed
[chrome #2] .  it second 1 ...
[chrome #2]  Passed
[chrome #2] .4 of 4 passed (0 skipped).
[chrome #2] SUCCESS: 4 specs, 0 failures, 0 skipped, 0 disabled in 4.884s.

loop with count value

[chrome #2] Using the selenium server at http://localhost:4444/wd/hub
[chrome #2] Started
[chrome #2] loopTest
[chrome #2] 0 of 0 passed (0 skipped).
[chrome #2] SUCCESS: 0 specs, 0 failures, 0 skipped, 0 disabled in 0.003s.
[chrome #2]
[chrome #2]
[chrome #2] No specs found
[chrome #2] Finished in 0.003 seconds

extdevelopment avatar Feb 04 '15 22:02 extdevelopment

I think this is answered with Hank's post above.

juliemr avatar Mar 17 '15 23:03 juliemr

@juliemr I think partially answered, http://stackoverflow.com/a/27874090 "Disadvantage is that since everything is in just 1 test, if 1 case out of 100 fails, you'll just get a single failure."

extdevelopment avatar Apr 02 '15 12:04 extdevelopment

Hi everyone,

I\ve found this nice npm package for data driven jasmine: https://www.npmjs.com/package/jasmine-data-provider ,

so now I have data in params like this:

params: {
    users: {
        admin_user: 'ADMIN-USER',
        manager_user: 'MANAGER-USER',
        supervisor_user: 'SUPERVISOR-USER',
        root_user: 'ROOT-USER',
        moderator_user: 'MODERATOR-USER'
    },

(but you can load them from json there.)

and use it like this:

using(Object.keys(params.users), function (data) {
    it('all user roles should...

hope this helps someone.

cvakiitho avatar May 29 '15 12:05 cvakiitho

I want to execute the test where I can specify the browsername, environement name, suite name in execution command as follows protractor conf.js browser=chrome env=staging suite=smoke

  1. Is that possible with Jasmine and Protractor and
  2. Can any one show me how to achieve that?

sachin-qe avatar Oct 14 '15 09:10 sachin-qe

Hi Sachin, Try following command protractor conf.js --capabilities.browserName="chrome" --suite smoke

Milan-kumar avatar Mar 02 '16 07:03 Milan-kumar

Hi All,

I am looking to run test very like extdevelopment above but I dont think the important bit of the issue is covered in Hanks post as it is the looping of dynamic value that is tricky.

In the code above the sticking point is in the for loop where I want to be able to count rows of table on page and then run a test per row

//protractor(jasmine) answere: No specs found, because this loop run, before beforeAll run //for (var int = 0; int < count; int++) { //with fixed constant value worked, but I want to use element.all.count() value for (var int = 0; int < 2; int++) { console.log('for loop', executionCounter++); its(); }

So I would like to be able to replace the 'int < 2' with 'int < someTableRowOnPage'. As far as can see looping through table rows and doing a test cannot be done using Jasmine Data Provider as this uses static files. If I do count elements on a page in the beforeAll and use the count in the for loop the test doesn't run. It needs a hard coded value in the for loop.

Any suggestion would be most welcome

lynn-fisher avatar May 08 '19 09:05 lynn-fisher