I have a test spec file whose purpose is to check for a booking reference in our application then check that the same reference is quoted in an email.
In the first part of the test I declare a variable called dbmRef
- I know this is working as I've got a console.log
that shows the contents of the variable.
Further down- on in the email system (Outlook.com), I have another variable called dbm
that finds the booking ref in the email body.
Finally, I have expect(dbm).toContain(dbmRef)
but this errors with Expected 'DBM040815' to contain undefined.
I'm assuming that Protractor cannot 'see' the first variable from further up the script...is that right? If so, how can I remedy please?
Herewith the code - not in final form!
/**********************
* Company: Guestline
* Product: DBM
* Author: D Redmayne
**********************/
var hotKeys = require('protractor-hotkeys');
describe('DBM Hotel', function() {
it('Confirmation', function() {
browser.ignoreSynchronization = true;
browser.sleep(500);
// assertions
expect(browser.getTitle()).toEqual('| Confirmation');
var conf1 = element(by.xpath(".//*[@id='root']/div[2]/div/div[2]/div/section/div[1]/div[2]/div/h4")).getText();
expect(conf1).toContain("DBM");
var conf2 = element(by.xpath(".//*[@id='root']/div[2]/div/div[2]/div/section/div[3]/div[2]/div[1]/div/div[2]/span/span/span")).getText();
expect(conf2).toContain("£50.00");
var dbmRef = element(by.xpath(".//*[@id='root']/div[2]/div/div[2]/div/section/div[1]/div[2]/div/h4")).getText().then(console.log);
// allows time for Outlook to capture email
browser.sleep(2000);
browser.get('https://outlook.com/');
browser.ignoreSynchronization = true;
browser.sleep(10000);
//chooses sign-in
element(by.xpath("html/body/section/div/div/nav/div/div/div/a")).click();
browser.sleep(500);
// enters credentials
element(by.xpath(".//*[@id='i0116']")).sendKeys('xxxxxx@outlook.com');
browser.sleep(1000);
element(by.xpath(".//*[@id='idSIButton9']")).click();
browser.sleep(500);
element(by.xpath(".//*[@id='i0118']")).sendKeys('pppppppp');
element(by.xpath(".//*[@id='idSIButton9']")).click();
browser.sleep(300);
expect(browser.getTitle()).toEqual('Mail - David Redmayne - Outlook');
browser.sleep(10000);
element(by.xpath("html/body/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div")).click();
browser.sleep(500);
var dbm = element(by.xpath("html/body/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div/div[3]/div/div/div/div/div[2]/div/div[1]/div/div/div/div[2]/div[1]/div/div/div/table/tbody/tr[3]/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/b")).getText();
expect(dbm).toContain(dbmRef);
});
});