Fill combobox and data driven testing

51 views
Skip to first unread message

Adela Karaman

unread,
May 25, 2015, 3:45:22 PM5/25/15
to casp...@googlegroups.com
Hello everybody,
I am trying to fill combobox, but it doesn't work.
I tried with filling like all other fields in form, but it throws error - no such css selector (but it is there).
After that I tried the other way, it pass, but value combobox is not selected.
My script is below.

My second question is about data driven testing - how can I read data from csv(or xml) file, and use this data for filling form?

Can anybody, please, help me?

casper.start('http://localhost:8080/StudentskiRadoviEE-war/faces/UnosStudenta.xhtml', function() {
    this.fillSelectors('form#frmUnosSTudenta', {
         'input[name="frmUnosSTudenta:txtImeStudenta"]':    'Milana',
   'input[name="frmUnosSTudenta:txtPrezimeStudenta"]':    'Mihajlovic',
    'input[name="frmUnosSTudenta:txtBrojIndeksa"]':    '21/11',
     'input[name="frmUnosSTudenta:txtGodinaStudija"]':    '3',
//COMBOBOX 1st TRY
    // 'input[name="frmUnosSTudenta:cbNivoiStudija"]':    '2',
    }, true);
   

    this.evaluate(function() {
//COMBOBOX 2nd TRY
        document.querySelector('name="frmUnosSTudenta:cbNivoiStudija"').selectedIndex = 2;  
       // COMBOBOX 3rd TRY
       //document.querySelector({
         //  type:'xpath',
        //path:'.//*[@id="frmUnosSTudenta:cbNivoiStudija_panel"]',
          
      // }).selectedIndex = 2;
      
      
        return true;
    });
    this.wait(5000);
    this.capture('screenshot.png');
    this.click({
        type:'xpath',
        path:'.//*[@id="frmUnosSTudenta:btnSacuvaj"]',
       
    });
 
    this.echo('success', 'INFO');
   
});
casper.run(function() {
       
    });



Adela Karaman

unread,
Jun 2, 2015, 12:46:27 PM6/2/15
to casp...@googlegroups.com
In case that somebody needs a solution, I found one for data driven testing:

var fs = require('fs');
var stArray = new Array();
casper.start('http://localhost:8080/StudentskiRadoviEE-war/faces/UnosStudenta.xhtml');
casper.then(function readFile() {
    stream = fs.open('C:/casperjs/bin/students.csv', 'r');
    line = stream.readLine();
    i = 0;
   
    while(line) {
        casper.echo(line);
        line = stream.readLine();
        var stSplited = line.split(',');
        var st = {ime:stSplited[0],prezime:stSplited[1],indeks:stSplited[2],godina:stSplited[3],nivo:stSplited[4]};
        stArray.push(st);
       
        i++;
    }
   
  
});
casper.then(function() {
for (i = 0; i < stArray.length; i++) {
 casper.echo(i);
  this.evaluate(function() {
        document.querySelector('name="frmUnosSTudenta:cbNivoiStudija"').selectedIndex = stArray[i].nivo;  

        return true;
    });
    this.fillSelectors('form#frmUnosSTudenta', {
         'input[name="frmUnosSTudenta:txtImeStudenta"]':    stArray[i].ime,
         'input[name="frmUnosSTudenta:txtPrezimeStudenta"]':    stArray[i].prezime,
         'input[name="frmUnosSTudenta:txtBrojIndeksa"]':    stArray[i].indeks,
        'input[name="frmUnosSTudenta:txtGodinaStudija"]':    stArray[i].godina,
    }, true);

   
  
   
    this.click({
        type:'xpath',
        path:'.//*[@id="frmUnosSTudenta:btnSacuvaj"]',   
    });

    this.echo('success', 'INFO');
   
}
 
 });
 

casper.run();

GANA DHAR

unread,
Dec 7, 2015, 5:05:30 AM12/7/15
to CasperJS
Hey buddy i tried the above solution but it is showing following error
TypeError: stream.readLine is not a function 

GANA DHAR

unread,
Dec 7, 2015, 5:08:17 AM12/7/15
to CasperJS
Actually i need this kind of ie data driven for the user login fields and also some other functionalities.
Reply all
Reply to author
Forward
0 new messages