mardi 28 avril 2015

casper.js: Switch popup ("tab") permanently

so my Situation is: I use casperjs 1.1.x (latest dl-version from page) together with phantomjs 1.9.8 on a windows os.

To make a long story short, my Problem in one sentence: I'm in need to switch my page permanently, for I have an "entrypage" where I add an ID and click a link which opens the app-page in a new tab via target=_blank.

I am aware of waitForPopup and withPopup-functions of casperjs, but sadly the withPopup-function changes the page back after one call.

this is my so-far test-scenario:

casper.test.begin('My Testsuite', function(test) {
casper.options.waitTimeout = 15000;
casper.start('http://myAppEntryPage/', function() {
    test.assertUrlMatch(/myAppEntryPage/, 'Casper starts on myAppEntryPage');  
    test.assertExists("#HyperLink1", 'Button -xxx- exists');
    test.assertExists("#HyperLink2", 'Button  -yyy- exists');
    test.assertExists("#TextBox1", 'Input  for zzz exists. Ready to go! \n\n');
})

casper.then(function(){
    this.sendKeys('input#TextBox1', '124733');
}).then(function(){
    this.test.assertField('TextBox1', '124733');
}).then(function(){
    this.click('#HyperLink2');
}).waitForPopup('http://myApp/configurator.aspx#Id=124733', function() {
    this.test.assertEquals(this.popups.length, 1);
}).withPopup('http://myApp/configurator.aspx#Id=124733', function() {
    this.test.assertTitle('Title2');
    //this.page = this.popups[1];
    console.log('Successfully changed to view! ' + this.getCurrentUrl());
}).waitForSelector('.list-weekdays', function(){ 
    //this is not working because I am in http://myAppEntryPage again.
    this.test.assertExists('.list-weekdays-day');
    console.log('App-Mainview loaded. Lines appearing.\n\n')
});

casper.run(function() {
    test.done();
    exit(0);
})
});

So as the comment above states, I am at http://myAppEntryPage instead of http://myApp/configurator.aspx#Id=124733 - the "popup" I want to be and work with for the rest of my Testsuite.

I just tried this:

this.page = this.popups[1];

inside of the withPopup-function, but this leads to an exception, so I am out of Ideas for now and hope you could help me out.

The relevant Part of the Output of my test-console is:

Successfully changed to Wochenansicht! http://myApp/configurator.aspx#Id=124733
FAIL ".list-weekdays" still did not exist in 15000ms
#    type: uncaughtError
#    file: testsuite.js
#    error: ".list-weekdays" still did not exist in 15000ms

#    stack: not provided
FAIL 8 tests executed in 18.525s, 7 passed, 1 failed, 0 dubious, 0 skipped.

So I think I am simply at the wrong page. I also tried to find other elements in the resulting main-page, especially higher in the dom-hierarchy, but with no luck.

So: Is there a way to permanently change the popup?

Would be great to hear from you!

Best regards, Dominik

Aucun commentaire:

Enregistrer un commentaire