Script showing error

Hi,

Can anyone please help on this.
Am getting the below: I had the right element locators and can see there is no issue on the application by manually logging in:
What else I should do, can you please take a look? Please let me know for additional info. Thank you in advance.

verifyTextPresent “ABC” STARTED at 34164ms.
verifyTextPresent SUCCEEDED.
Script execution failed (due to an unhandled promise rejection): Error: Job timed-out after 180s
Script execution failed: TimeoutError: Timed-out waiting for element to be located using: [object Object]
Wait timed out after 150544ms
Error: Job timed-out after 180s
at BrowserScriptRunner.value (/opt/runtimes/4.0.0/modules/synthetics-runner/lib/runner/0.6.0/browser-script-runner.js:66:67)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)

Error: Job timed-out after 180s

Hi, @TARIGS1: Synthetics scripts have a fixed time limit of 180 seconds. You will need to reduce the amount of work your script does so that it can complete in less than 3 minutes.

1 Like

Hi Phil,
Appreciate your prompt reply. As you are NR moderator, would it be possible to see the inside of the script?

Spent good amount of time, but cannot figure out and thought of taking your help.

what is happening is: when I enter text, going to error page and is not happening when I do manually.

For ex:

log(36, ‘36 setElementText “12345” in the Search Clients text field’);

// return $browser.waitForAndFindElement(By.xpath(’//input[@id=“customer_data”]’), 200); })

return $browser.waitForAndFindElement(By.id(“customer_data”), DefaultTimeout); })

.then(function (el) {

el.clear();

el.sendKeys(“12345”);

//el.sendKeys($driver.Key.ENTER)

})

.then(function(){return $browser.sleep(5000);})

Another possibility is that Synthetics scripts run in Chrome version 72; you are probably using a newer version of Chrome when you perform the actions manually. It is possible that your site is not compatible with Chrome 72.

No, the reason am telling no is , rest of the script to login and do other validation is going as supposed to, that being said, should not be chrome issue. that is correct, rt?

I don’t know, I am just telling you why a script may fail but performing the task in your own browser succeeds. If you would like to post a script here that reproduces the issue, perhaps the community can help you.

got it, sure.

Below is the script:

Concern after the:

      .then(function () {
        log(35, '35 clickElement "customers account home"');
        return $browser.waitForAndFindElement(By.xpath('//a[@class="menu-item-heading"]'), 200);
      })
      .then(function (el) { el.click(); })
      .then(function () { return $browser.sleep(5000); })
      .then(function () {
        log(10, 'verifyTextPresent "find customer"');
        $browser.waitForAndFindElement({ xpath: '//span[contains(text(), "find customer ")]' }, DefaultTimeout)
        // $browser.waitForAndFindElement({xpath: '//span[@for='customerInfo]'}, DefaultTimeout)
        console.log('verifyTextPresent SUCCEEDED.');
      })
      .then(function () {
        log(36, '36 setElementText "123456" in the Search customers text field');
        return $browser.waitForAndFindElement(By.id('customerInfo'), DefaultTimeout);
      })
      .then(function (el) {
        el.clear();
        el.sendKeys('1234567');
        el.sendKeys($driver.Key.ENTER)
      })

Script:

var user = 'test';
var ScriptTimeout = 180000;
var DefaultTimeout = 150000;
var UserAgent = 'default';
var assert = require('assert'),
  By = $driver.By,
  browser = $browser.manage(),
  startTime = Date.now(),
  stepStartTime = Date.now(),
  prevMsg = '',
  prevStep = 0,
  lastStep = 9999,
  VARS = {};

var log = function (thisStep, thisMsg) {
  if (thisStep > 1 || thisStep == lastStep) {
    var totalTimeElapsed = Date.now() - startTime;
    var prevStepTimeElapsed = totalTimeElapsed - stepStartTime;
    console.log('Step ' + prevStep + ': ' + prevMsg + ' FINISHED. It took ' + prevStepTimeElapsed + 'ms to complete.');
    $util.insights.set('Step ' + prevStep + ': ' + prevMsg, prevStepTimeElapsed);
  }
  if (thisStep > 0 && thisStep != lastStep) {
    stepStartTime = Date.now() - startTime;
    console.log('Step ' + thisStep + ': ' + thisMsg + ' STARTED at ' + stepStartTime + 'ms.');
    prevMsg = thisMsg;
    prevStep = thisStep;
  }
};

function isAlertPresent() {
  try {
    var thisAlert = $browser.switchTo().alert();
    return true;
  } catch (err) { return false; }
}

function isElementSelected(el) { return $browser.findElement(el).isSelected(); }

function isTextPresentIn(text, selector) {
  try {
    return $browser.findElement(selector)
      .getText()
      .then(function (wholetext) {
        return wholetext.indexOf(text) != -1;
      })
  } catch (err) {
    return false;
  };
}

function isTextPresent(text) {
  return isTextPresentIn(text, By.tagName('html'));
}

// *** mmm code ***
var tr1 = 'good';

/** BEGINNING OF SCRIPT **/
// Setting User Agent is not then-able, so we do this first (if defined and not default)
if (UserAgent && (0 !== UserAgent.trim().length) && (UserAgent != 'default')) {
  $browser.addHeader('User-Agent', UserAgent);
  console.log('Setting User-Agent to ' + UserAgent);
}

// Get browser capabilities and do nothing with it, so that we start with a then-able command
$browser.getCapabilities().then(function () { })
  // Step 1
  .then(function () {
    return $browser.get('url');
  })

  //*****************************************
  //Add the cookie that was retrieved from Insights, if one was found
  .then(function () {
    return $browser.manage().addCookie({ name: mfaCookieName, value: cookieValue, path: '/', domain: 'abc.net', isSecure: true });
  })
  //Make sure the cookie was added successfully.
  .then(function () {
    return $browser.manage().getCookie(mfaCookieName);
  })
  .then(function (cookie) {
    if (cookie != null) {
      console.log('Cookie was added successfully in the last step.');
      $util.insights.set('PrevCookieUsed', 'True');
    }
    else {
      console.log('Cookie add failed!');
    }
  })
  //******************************************
  // Step 2
  .then(function () {
    log(2, 'clickElement "headerDropDown"');
    return $browser.waitForAndFindElement(By.css(".display-desktop > span"), DefaultTimeout);
  })
  .then(function (el) { el.click(); })
  // Step 3
  .then(function () {
    log(3, 'setElementText "usernameMenu"');
    return $browser.executeScript('return document.querySelectorAll("bolt-textfield")[1].shadowRoot.querySelector("input")');
  })
  .then(function (el) {
    console.log('Username: ' + user);
    console.log('MFA: Yes');
    el.clear();
    el.sendKeys(user);
  })
  .then(function () {
    log(4, 'setElementText "passwordMenu"');
    return $browser.executeScript('return document.querySelectorAll("bolt-password")[1].shadowRoot.querySelector("input")');
  })
  .then(function (el) {
    el.clear();
    el.sendKeys(originalPW);
  })
  .then(function () {
    log(5, 'clickElement "Log In"');
    return $browser.executeScript('return document.querySelectorAll("bolt-button")[1].shadowRoot.querySelector("button")');
  })
  .then(function (el) { el.sendKeys('\n'); })
  .then(function () {
    log(6, 'Waiting for login to complete');
    return $browser.waitForAndFindElement(By.xpath('//user-name[@class="display-desktop"]//span[contains(text(),"' + user + ' ' + user + '")]'), DefaultTimeout);
  })
  // Step 6
  .then(function () {
    log(34, '34 clickElement "My business"');
    return $browser.waitForAndFindElement(By.xpath('//span[@id="menu-tabs-servicing]"), DefaultTimeout); })
      .then(function (el) { el.click(); })

      .then(function () {
        log(35, '35 clickElement "customers account home"');
        return $browser.waitForAndFindElement(By.xpath('//a[@class="menu-item-heading"]'), 200);
      })
      .then(function (el) { el.click(); })
      .then(function () { return $browser.sleep(5000); })
      .then(function () {
        log(10, 'verifyTextPresent "find customer"');
        $browser.waitForAndFindElement({ xpath: '//span[contains(text(), "find customer ")]' }, DefaultTimeout)
        // $browser.waitForAndFindElement({xpath: '//span[@for='customerInfo]'}, DefaultTimeout)
        console.log('verifyTextPresent SUCCEEDED.');
      })
      .then(function () {
        log(36, '36 setElementText "123456" in the Search customers text field');
        return $browser.waitForAndFindElement(By.id('customerInfo'), DefaultTimeout);
      })
      .then(function (el) {
        el.clear();
        el.sendKeys('1234567');
        el.sendKeys($driver.Key.ENTER)
      })
      .then(function () { return $browser.sleep(5000); })

      .then(function () {
        log(37, '37 clickElement magnifying glass search icon');

        return $browser.waitForAndFindElement(By.id('searchSubmitExactId'), DefaultTimeout);
      })
      .then(function (el) { el.click(); })

      .then(function () {
        log(38, '38 waitForAndFindElement "123456"');
        return $browser.waitForAndFindElement(By.xpath('//*[@id="policyNumber"][contains(text(), "123456")]'), 225);
      })

      // Step 39
      .then(function () {
        log(39, '39 waitForAndFindElement " VALUE"');
        return $browser.waitForAndFindElement(By.xpath('//*[@id="customerSummaryAJAXLoaderArea"]/div[1]/div[3]/div[2]/div[2][contains(text(), "Value")]'), DefaultTimeout);
      })
      // Step 40
      .then(function () {
        log(43, '43 clickElement "Log out"');
        return $browser.waitForAndFindElement(By.css(".clrPointer"), DefaultTimeout);
      })
      .then(function (el) { el.click(); })
      .then(function () {
        log(lastStep, '');
        console.log('Browser script execution SUCCEEDED.');
      }, function (err) {
        console.log('Browser script execution FAILED.');
        throw (err);
      });

The issue seems simple to me, you are using waitForAndFindElement and the script is timing out because it can’t find the element:

$browser.waitForAndFindElement({ xpath: '//span[contains(text(), "find customer ")]' }, DefaultTimeout)

Or it can’t find this one:
return $browser.waitForAndFindElement(By.id('customerInfo'), DefaultTimeout)

The script is “waiting” for 150000ms because it can’t find that xpath. Your DefaultTimeout is set to 150000. The script is ultimately failing because that element isn’t there.

1 Like