Scripted Browser Test Fails with Timeout due to Forwarding

I am trying to implement a scripted browser test, which tries opening a URL which will then redirect to another site to authenticate (its a SAML auth). I tried to get some contents of the login page i am redirected to when trying the same in my Browser. In the error logs of the script there is a responsecode 401 from the first site because i dont have SAML auth info yet. Finally i get a timeout error.

So the same process in a browser starts with opening the site, getting redirected to a Salesforce login page, inserting the credentials, ticking a checkbox and hit login. I then get redirected to the orginial URL again, seeing the homepage of the site.

Here is the script i use:

var assert = require('assert');

var username = encodeURIComponent('username');
var password = encodeURIComponent('password');
var url = 'https://' + username + ':' + password + '@urlvalue;

$browser.get(url).then(function(){
  // Check the login page class title matches "Willkommen zurück"
  return $browser.waitForAndFindElement($driver.By.className('title')).then(function(element){
    return element.getText().then(function(text){
      assert.equal('Willkommen zurück', text, 'Login page title did not match');
    });
  });
});

I think you want to try to mimic the behavior in the browser. I don’t think you can pass the username and password in the URL as a valid SAML authentication. This is how Basic authentication works in the browser, but the credentials are sent over the Internet insecurely. In Synthetics, you can allow the browser to follow those links and just look for the resulting textbox to ‘type’ credentials into (using putText method). So, the number of steps is going to increase. One step to get the page, another to click login, another step to putText into username/password, and a final step to click login on that page. You can also try recording a test like this using Selenium IDE browser plugin (and then export to Synthetics format) to help create the steps.

1 Like

Hey @mcaron,

Yes i want to mimic the behavior of the browser. The url username and password is needed for basic auth, as you already mentioned. So the page i want to monitor at first has basic auth in front of the start page. But the problem is, that when trying to hit the start page, i get a 401 back und the browser gets redirected to a salesforce login page. The synthetics check does not get across this redirect/ 401 error it seems. That’s where i am stuck right now.

The basic auth in a URL is not performing a SAML authentication the way that you are passing the username and password. Below is snippet from a test that logs into my piHole website. The key here is how I am just using the browser to find and enter text into the inputs in the HTML rather than passing auth in the URL. I’m all over the map finding the elements on the page by ID and XPATH here, but that’s the basic idea: automate the steps a user would take in their browser rather than passing the auth in the URL. Also, use Secure Credentials for sensitive data.

.then(function(){
  $browser.get("http://192.168.0.222:8089/admin/index.php")
.then(function(){
  $browser.waitForAndFindElement(By.xpath("//span[contains(.,\'Login\')]"),DefaultTimeout)
  .then(e=>(e.click()))})
.then(function(){
  $browser.waitForAndFindElement(By.id("loginpw"),DefaultTimeout)
  .then(e=>(e.sendKeys($secure.PIHOLE_PW)))})
.then(function(){
  $browser.waitForAndFindElement(By.xpath("//button[contains(.,\' Log in\')]"),DefaultTimeout)
  .then(e=>(e.click()))})