I am running into an error, when including vanilla JS in nightmare.js. I want to make sure that every email in my array is inputted into the system. A for loop would be ideal, but I have continually run into error such as:
Search failed: Nothing responds to "goto"
Here is my code:
var jquery = require('jquery');
var Nightmare = require('nightmare');
var nightmare = Nightmare({
show: true,
dock: true
});
var siteName = "*********";
var username = "*********";
var password = "*********";
var outboundEmailArray = [
{
"from_name": "TestOutbound",
"email_username": "array1",
"email_domain": "salesforce.com",
"email_domain": "salesforce.com",
"reply_to": "[email protected]"
},
{
"from_name": "Tester",
"email_username": "array2.0",
"email_domain": "salesforce.com",
"email_domain": "salesforce.com",
"reply_to": "[email protected]"
}
];
//
// var outboundEmailSetup = function(outboundEmail){
// nightmare
// .goto("https://" + siteName + ".desk.com/login/new")
// .type("input[id='user_session_email']", username)
// .type("input[id='user_session_password']", password)
// .click("#user_session_submit").wait(2000)
// .goto("https://" + siteName + ".desk.com/admin/settings/mail-servers")
// .click("#a-add-modal").wait(2000)
// .type("input[id='postmark_outbound_mailbox_fromname']", outboundEmail.from_name).wait(2000)
// .type("input[id='email_username']", outboundEmail.email_username).wait(2000)
// .click("#from_select_4999").wait(2000)
// .type("input[id='postmark_outbound_mailbox_reply_to']", outboundEmail.reply_to).wait(2000)
// .click("#postmark_commit").wait(2000)
// .click(".a-modal-bottom .a-button").wait(2000)
// .evaluate(function() {})
// .end()
// .then(function(result) {
// console.log(result)
// })
// .catch(function(error) {
// console.error('Search failed:', error);
// });
// }
var outboundEmailSetup = function(i){
if(i < outboundEmailArray.length) {
nightmare
.goto("https://" + siteName + ".desk.com/login/new")
.type("input[id='user_session_email']", username)
.type("input[id='user_session_password']", password)
.click("#user_session_submit").wait(2000)
.goto("https://" + siteName + ".desk.com/admin/settings/mail-servers")
.click("#a-add-modal").wait(2000)
.type("input[id='postmark_outbound_mailbox_fromname']", outboundEmailArray[i].from_name).wait(2000)
.type("input[id='email_username']", outboundEmailArray[i].email_username).wait(2000)
.click("#from_select_4999").wait(2000)
.type("input[id='postmark_outbound_mailbox_reply_to']", outboundEmailArray[i].reply_to).wait(2000)
.click("#postmark_commit").wait(2000)
.click(".a-modal-bottom .a-button").wait(2000)
.evaluate(function() {})
.end()
.then(function(result) {
console.log(result)
})
.catch(function(error) {
console.error('Search failed:', error);
});
outboundEmailSetup(i+1);
}
}
outboundEmailSetup(0);
Ideally, it would loop through the outboundEmailArray, run the function to input the emails into the system, repeat until it has reached the end of the array.