-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What to do if i need to login user before run the Wraith? #446
Comments
I've tried two methods for this with forms authenticated pages.
The cookie is added like this before the page.open... phantom.clearCookies(); phantom.addCookie({ page.open(url, function(status) {... |
I can't guarantee this is correct but the script was something like this, literally pasting the username and password in and clicking submit. module.exports = function (phantom, ready) {
phantom.evaluate(function(){
if ($("#logonContainer").length > 0)
{
// Enter username and password in the input fields
$("#UserName").val("yourusername");
$("#Password").val("yourpassword");
// Click the submit button
clickElement($("input:submit")[0]);
}
});
});
});
setTimeout(function(){ready();}, 20000);
} Note: that the setTimeout has to be long enough to give time for the logon page to redirect the browser back to the original page that you were trying to capture. ...and the config file refers to the script like this... before_capture: 'javascript/logon.js' |
Hi SimonKeep, Can you elaborate this in detail, even am facing the same issue. Regards |
i need the same bro. Please, guys, who can help? |
Please help. I am also looking for image comparison, once I have logged in. If you could provide step by step configuration steps, that would be great. |
@SimonKeep provides a good way of doing this in his comment (thanks, Simon!), but leaves out one detail, which I'll fill in now. This kind of thing will vary for every user, so unfortunately we can't do any more than provide general guidance. Though Simon's code is a good starting point, the contents of your file will have to be tweaked according to your needs. E.g. the ID of your username/password fields will be different. Also if you don't have jQuery in the page you'll have to rewrite in vanilla JS. His approach will work if your login script redirects you to the page you want to test - but assuming your login script always redirects you to, say, Take this example YAML file: paths:
'dashboard': '/dashboard'
'account': '/account'
'settings': '/settings'
before_capture: 'js/login.js' In the module.exports = function (casper, ready) {
casper.open('/login.php');
casper.evaluate(function () {
// write your JS which fills in your login form and submits it here
});
// at this point we're now at /dashboard - so need to redirect ourselves to the
// page we wanted to test in the first place, e.g. /settings
casper.thenOpen(casper.page.url); // casper.page.url is the URL Wraith originally tried to load (before /login.php)
ready(); Alternative approachIf you have control over the server-side code of the website you want to test, you could use the So for example, you could visit Hope that's useful! We can't really provide any more specific advice I'm afraid. Good luck with your testing! |
I have site. But a lot of pages are available only for registered user. How to use Wraith in that case? Please advice.
The text was updated successfully, but these errors were encountered: