Reputation: 1375
I have a weird scenario:
In my automation, i have to create a user. On creation, a password wil be generated and sent to his/her email id. How can i automate to retrieve the password in his/her email(NOTE:I have to open a new window to go to his/her email and enter his/her credentials and open the particular mail which has the sent password and copy it) and come back to my application and login with his/her username and password? Pretty confusing rite
And also how i can i switch to another tab(supposingly it is not an angular-app), and execute actions to enter username and password of his email)
Upvotes: 0
Views: 513
Reputation: 1375
After a lot of searching and unserstanding, it turns out that you have to mock your smtp server and send mails to that server, to test the mailing functionality of your application. In order to make life easy there are some softwares available like mailCatcher, mailLisetner.
But my preference would be mailHog. It is really very easy to setup(actually just download the .exe) and make your application to send mails to it. It doesn't require any fancy installation steps( like mailCatcher , guys its really hectic to install it ) or any coding(like mailListener).
MailHog, it is...!
Upvotes: 0
Reputation: 3266
For the emails, you can use a package called mail-listener. You can follow the instructions on this answer, I've done it myself and it was relatively easy to setup. Then you can get the password from the parsed email.
And as far as switching to other tabs, you can use getAllWindowHandles()
, something like this:
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[1];
browser.switchTo().window(newWindowHandle).then(function () {
// do stuff
});
});
Since it's non-Angular page, you'll need to set browser.ignoreSynchronization = true
. You can do this in the function when you switch window handles, or you may even want to do it right before that step. You'll need to use some Expected Conditions to control test flow. Find the necessary elements you need to interact with on the non-Angular page, i.e.:
var EC = protractor.ExpectedConditions;
var el = element(by.id('loginForm'));
browser.wait(EC.visibilityOf(el));
// do stuff
Edit:
To open a new tab yourself via Protractor, you can use executeScript()
. i.e.
browser.executeScript("window.open('http://www.google.com')");
Edit 2:
For setting up mail-listener, the code provided in the linked question was pretty much copy/paste for me with the exception of username
, password
, and host
. The username/password will be the same user you are trying to login as. For host, it varies by email server. You should be able to find it by googling "imap host for microsoft exchange (or whatever server you are using)" or going to the settings of that email server.
Only other code I really added to that function was logging errors which might help identify your problem and why you can't connect. You can put this in the onPrepare()
function of your config file:
mailListener.on("error", function(err){
console.log(err);
});
Upvotes: 1