Search code examples
emailprotractore2e-testingangular-e2e

E2E - how to test that confirmation email is being sent by register process?


I do have a register process/form which passes email, password, confirmPass and a tc checkbox which has a boolean value.

When the user submits the form, an open dialogue with a text opens and in the other hand an email is being sent to the user to confirm his registration. Everything works fine.

To run an E2E protractor test for this process I wrote wrote the following code:

it("Should register the user and send confirmation email", () => {

    page.getInputFields().userEmailInput.sendKeys("myFirstName.myLastName@domain-xxx.com");
    page.getInputFields().userPassInput.sendKeys('!Q2w3e4r');
    page.getInputFields().userConfirmPass.sendKeys('!Q2w3e4r');
    element(by.tagName('mat-checkbox')).click();

    expect( page
        .getInputFields()
        .userEmailInput.getAttribute("value") ).toEqual("myFirstName.myLastName@domain-xxx.com");

    expect(page
        .getInputFields()
        .userPassInput.getAttribute("value") ).toEqual('!Q2w3e4r');

    expect(page
        .getInputFields()
        .userConfirmPass.getAttribute('value') ).toEqual('!Q2w3e4r');

    element( by.tagName('mat-checkbox') ).isSelected().then(function(selected) {
        if (selected) {
            element( by.name('mat-checkbox') ).click();
            expect( page.getInputFields().userAccept.isSelected() ).toBe(true);
            page
        .getInputFields()
        .submitButton.click();
        }
    });
});

The test also runs without error(s). But my issue is that I'am expecting after the test that I get the confirmation email in my inbox, which prove me in the other hand that the test was 100% successful, but I just don't get the confirmation email which means that the test isn't really running as expected.

  1. Is it possible to run the test so that a confirmation email is being sent?
  2. Is the code for the test wrong and I do have a logic error in it?
  3. Has it to do with the open dialogue window which should be opened after clicking on submitButton and I'am not testing it (in my code)?

One thing I still have to mention is that the button is disabled if user data are missing and the tc (checkbox) isn't checked.


Solution

  • Issue is fixed and here is the working code:

    it("Should register the user and send confirmation email", () => {
    
        page.getInputFields().userEmailInput.sendKeys("myFirstName.myLastName@domain-xxx.com");
        page.getInputFields().userPassInput.sendKeys('!Q2w3e4r');
        page.getInputFields().userConfirmPass.sendKeys('!Q2w3e4r');
        element(by.tagName('mat-checkbox')).click();
    
        expect( page
            .getInputFields()
            .userEmailInput.getAttribute("value") ).toEqual("myFirstName.myLastName@domain-xxx.com");
    
        expect( page
            .getInputFields()
            .userPassInput.getAttribute("value") ).toEqual('!Q2w3e4r');
    
        expect( page
            .getInputFields()
            .userConfirmPass.getAttribute('value') ).toEqual('!Q2w3e4r');
    
        browser.wait(protractor.ExpectedConditions.elementToBeClickable( element( by.name('submitForm') ) ), 100000)
                .then ( () => {
                    browser.actions().mouseMove( element( by.name('submitForm') ) ).click().perform();
                }).then ( () => {
                    browser.sleep(500);
                    browser.actions().mouseMove( element( by.name('submitForm') ) ).click().perform();
                });
    
    });
    

    The following posting was very helpful!