How to write "If X .Then" logic?

Currently, we have a standard script to access a URL then log in using secure credentials. In the case of our website’s maintenance page being up, the synthetic monitor should not trigger a fail case. The logic I have so far is like so:

$browser.get("https://URL.com/").then(function(){

  // look for maintenance page
  $browser.getTitle().then(function(title) {
    if(title === "Site Maintenance Page"){
      $browser.takeScreenshot()
      return title
    }
  })

  return $browser.findElement($driver.By.id("userid")).sendKeys($secure.username); 
}).then(function(){
  return $browser.findElement($driver.By.id("continue")).click();
}).then(function(){
  return $browser.waitForAndFindElement($driver.By.id("password")).sendKeys($secure.PW)
}).then...[continues login flow]

I’d like for the script to end with a success response if the user is redirected to the maintenance page, rather than continue the logic and fail the rest of the script cases. Is there a way to include a conditional with the .then blocks (say, if maintenance==true {success}, else {.then(…)} ?

Hi, @christopher.lee2: It’s just JavaScript:

if (condition is true) {
   // code is executed
} else {
   // code is executed
}
1 Like

There is an example that I posted below

1 Like