petecoop / phantasma

A high level promise based wrapper for phantomjs
ISC License
33 stars 8 forks source link

I have coded an app that worked perfectly... #16

Closed Mako-L closed 8 years ago

Mako-L commented 9 years ago

And today I tried it again and it doesn't work anymore which is very weird... i get this:

Unhandled rejection TimeoutError: operation timed out
    at afterTimeout (C:\Arya\node_modules\phantasma\node_modules\bluebird\js\mai
n\timers.js:11:15)
    at timeoutTimeout (C:\Arya\node_modules\phantasma\node_modules\bluebird\js\m
ain\timers.js:53:9)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
    at process.__makeCall (node.js:420:23)

and this:

[TimeoutError: operation timed out]

for every click().wait() methods and it worked perfectly before I don't understand what is wrong with it. I tried adding 'timeout' option or the ph instance , tried 10 sec, then 15 sec it seems to solve the first timeout error but only sometimes witch is also very weird. I updated my phantomjs to 2.0. That didn't fix anything. I'm open to suggestions. Thank you ^_^

petecoop commented 9 years ago

hmm there might be an issue with .wait, I will have to do some testing to check.

Could provide an example of your code? Doesn't need to be your actual code just some example of what you are doing e.g. multiple click's and waits etc

Mako-L commented 9 years ago
var ph = new Phantasma(options);

var info = {
    number: 0,
    user: '',
    pass: '',
    path: ''
};

var filearray = fs.readdirSync(info.path);

var phase2 = function (i) {
    if (i < filearray.length) {
        var file = filearray[i];
        var t = file.substr('extension');
        var n = t + ' test';
        var s = '';
        ph.open('link')
            .type('input[id="test1"]', t)
            .type('input[id="test2"]', 'test')
            .evaluate(function (n) {
                document.querySelector('div[contenteditable="true"]').textContent = n;
                document.querySelector('select[name="test3"]').value = "2";
            }, n).evaluate(function () {
                doSubmit();
            })
            .evaluate(function () {
                doSubmit();
            }).wait()
            .evaluate(function (link) {
                return document.querySelector('a[class="test4"]').toString().substring(35, 48);
            }).then(function (number) {
                param.number = number;
            })
            .click('a[class="buttonTest"]').wait()
            .then(function (Qnumber) {
                console.log("Connecting to page...");
                console.log(param.number)
                return ph.open('http://127.0.0.1:3000/page/' + param.number)
            })
            .type('input[name="test5"]', t)
            .type('input[name="test6"]', price)
            .upload('input[class="file"]', param.path)
            .evaluate(function (n) {
                document.querySelector('div[test="true"]').textContent = n;
            }, n)
            .click('a[class="buttonTest2"]').catch(function (e) {
                console.log(e)
            }).wait().delay(1000)
            .click('a[class="buttonTest3"]').catch(function (e) {
                console.log(e)
            }).wait()
            .evaluate(function (link) {
                return document.location.href
            }).then(function (url) {
                console.log(url)
                if (url != 'http://127.0.0.1:3000/') {
                    return ph.click('a[class="buttonTest4"]').catch(function (e) {
                        console.log(e)
                    }).wait()
                }
            })
            .open('http://127.0.0.1:3000/')
            .finally(function () {
                console.log('done!');
                if (i != filearray.length) {
                    phase2(i + 1);
                } else {
                    ph.exit()
                }
            });
    }
}

var login = function () {
    ph.open("http://127.0.0.1:3000/")
        .type('input[name="username"]', param.user)
        .type('input[name="password"]', param.pass)
        .click('a[class="LoginButton"]')
        .wait()
        .catch(function (e) {
            console.log('error', e);
            login();
        })
        .finally(function () {
            console.log('done!');
            phase2(0);
        });
}

login();

Ok so this is an example of my code ^_^

petecoop commented 9 years ago

Hmm I'll have to see if I can replicate this...

Do you know at which step it freezes?

Are you duplicating your evaluates here?

.evaluate(function () {
  doSubmit();
})
.evaluate(function () {
  doSubmit();
}).wait()
Mako-L commented 9 years ago

No it's just another page and I had an .wait() there before but I also thought that this is causing the bug and freezing the application by suspending the activity flow . I will answer much fast from now. ^_^ Also if you have some Ideas of what functions I might add to the framework I'm listening and opened to help you code them.

alixaxel commented 9 years ago

@petecoop Running into the same issue with the provided example.

https://github.com/petecoop/phantasma#examples

Unhandled rejection TimeoutError: operation timed out
    at afterTimeout (/home/alix/Desktop/electro/node_modules/phantasma/node_modules/bluebird/js/main/timers.js:11:15)
    at timeoutTimeout (/home/alix/Desktop/electro/node_modules/phantasma/node_modules/bluebird/js/main/timers.js:53:9)
    at Timer.listOnTimeout (timers.js:119:15)
petecoop commented 9 years ago

@alixaxel just tested the example and it works fine for me, what version of phantomjs do you have installed?

idrakimuhamad commented 9 years ago

I got an error too testing this example.

ph.open('https://duckduckgo.com')
  .type('#search_form_input_homepage', 'phantomjs')
  .click('#search_button_homepage')
  .wait()
  .catch(function (e) {
    console.log('error', e);
  })
  .finally(function () {
    console.log('done!');
    ph.exit();
  }).on('onUrlChanged', function (url) {
    console.log('url change', url);
  });

The console:

url change https://duckduckgo.com/
error [TimeoutError: operation timed out]
done!

I'm running phantomjs v2.0.0.

It appear to be related to wait() function. Removing it stopped the error, but I can't figure out a way to replace it.

EDIT

Well it appear not necessarily related to only wait(). I tried with my own project, just open() and screenshot(), it returned timeout. At times, it work, but once the timeout appear, it failed for anything else. It only work if I set in the Phantasma instances a timeout and that will work, but a long process will still throwing timeout. I tried set to 60000 it appear to resolve most of the timeout problem, but, something definitely wrong.

petecoop commented 9 years ago

@idrakimuhamad this works fine for me:

url change https://duckduckgo.com/
url change https://duckduckgo.com/?q=phantomjs
url change https://duckduckgo.com/?q=phantomjs
url change https://duckduckgo.com/?q=phantomjs&ia=about
done!

So not really sure what is causing your issue, other than the page taking a while to load or something...

idrakimuhamad commented 9 years ago

Maybe you can try this one that I have. Whenever I put a wait(), it will hangs and nothing happened. If I removed it, the console properly triggered.

ph.open('https://cas2.northport.com.my/myapp/wa/r/nmbctr')
    .click('button#ge168')
    .wait()
    .then(function () {
        console.log('Done Load');
    })
    .catch(function (e) {
            console.log('error', e);
    })
    .finally(function () {
            console.log('done!');
            ph.exit();
            res.ok();
    });

What could be the caused do you think?

petecoop commented 9 years ago

I guess in that case you are entering a username and password first and then calling wait? For me the page is taking at least 12 seconds to load in Chrome, so the timeout needs to be extended to reflect that - wait will also take the timeout into account, and expects the previous action to cause a new page to load