In order to perform Basic Authentication within URL in Testsigma, you can use the following format in the Go to testdata NLP Statement:

Go to http://username:password@hostname.com

                         (or)

Go to  https://username:password@hostname.com


In case if https://username:password@hostname.com is not working, please use custom function for https:// or http://  authentication. Refer the example below to create custom function for authentication.


Using Custom Function for Basic Authentication


1. Create a Custom Function with the below code. Please refer for more details - How to create and use Custom Functions in Testsigma?


import org.openqa.selenium.WebDriver;
import com.testsigma.customfunc.common.CustomTestStep;
import com.testsigma.customfunc.result.TestStepResult;
import com.testsigma.customfunc.result.ResultConstants;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Alert;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.Capabilities;


import com.testsigma.customfunc.common.TestsigmaCustomFunctions;

public class Authentication extends TestsigmaCustomFunctions{
 @CustomTestStep
  public TestStepResult authenticationURL(String url, String username, String password) throws InterruptedException {
Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
String browser = cap.getBrowserName();
if(browser.equals(BrowserType.CHROME) || browser.equals(BrowserType.GOOGLECHROME)) {
  if(url.startsWith("https://")) {
    url = url.replace("https://", "https://" + username + ":" + password + "@");
  } 
  else  {
    url = url.replace("http://", "http://" + username + ":" + password + "@");
  }
  driver.get(url);
} else if (browser.equals(BrowserType.FIREFOX)) {
  driver.get(url);  
  Alert alert = driver.switchTo().alert();
   alert.sendKeys(username + Keys.TAB.toString()+ password);
  alert.accept();
  Thread.sleep(3000);
  alert.sendKeys(username + Keys.TAB.toString()+ password);
  alert.accept();
   Thread.sleep(3000);
} else if (browser.equals(BrowserType.IE)) {
  if(url.startsWith("https://")) {
    url = url.replace("https://", "https://" + username + ":" + password + "@");
  } else {
    url = url.replace("http://", "http://" + username + ":" + password + "@");
  }
  driver.get(url);
} else {
  driver.get(url);
}
      TestStepResult result = new TestStepResult();
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("Successfully Executed");
return result;
  }

}


2. Once the Custom Function is compiled and saved successfully, go to Create Test Step page, Select the Custom Function option and then select the Function name from the list.


3. Enter the following value as Custom Function arguments - URL, Username, Password and click on Create.


4. We need to add two Capabilities for hassle-free Execution. In Create Execution Configuration(Normal Execution) or Create Dry Run(Dry Run) page, add the following Desired Capabilities.


  • acceptInsecureCerts :  true
  • acceptSslCerts            :  true



That's all we need to perform for Basic Authentication in URL.


Happy Automation!