+1 vote
1 view
in DevOps and Agile by (19.8k points)

FAILED CONFIGURATION: @BeforeClass createDriver org.openqa.selenium.WebDriverException: Unable to parse remote response: Misconfigured -- Sauce Labs Authentication Error. You used username 'null' and access key 'null' to authenticate, which are not valid Sauce Labs credentials. The following desired capabilities were received: {'browserName': 'Chrome', 'build': 'Selenium_Soucelabs_2', 'name': 'Testing on windows 10', 'passed': 'true', 'platform': 'WIN10', 'version': '66.0'}

Here I'm unable to run my script with this configuration please help me what is wrong with this for testing here I use sauce lab, testng in the script which is not mentioned in this code,I followed script from here:"https://github.com/saucelabs-sample-test-frameworks/Java-TestNG-Selenium/blob/master/src/test/java/com/yourcompany/Tests/TestBase.java"

package Checkout;

import org.testng.asserts.SoftAssert;

import java.lang.reflect.Method;

import java.net.MalformedURLException;

import java.net.URL;

import java.rmi.UnexpectedException;

import java.util.concurrent.TimeUnit;

import org.testng.ITestResult;

import org.testng.annotations.*;

import org.openqa.selenium.*;

import org.openqa.selenium.interactions.Actions;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.Select;

import org.openqa.selenium.support.ui.WebDriverWait;

public class TestBaseFR {

Object verificationErrors;

private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();

private ThreadLocal<String> sessionId = new ThreadLocal<String>();

SoftAssert softAssert=new  SoftAssert();  

public static final String BUILDTAG = System.getenv("BUILD_TAG");

// enter your saucelabs user name here

public static final String USERNAME = System.getenv("SAUCE_USERNAME");

// enter your access key here

public static final String ACCESS_KEY = System.getenv("SAUCE_ACCESS_KEY");

public static final String SauceLabURL = "http://" + USERNAME + ":" + ACCESS_KEY

+ "@ondemand.saucelabs.com:80/wd/hub";

/**

     * DataProvider that explicitly sets the browser combinations to be used.

     *

     * @param testMethod

     * @return Two dimensional array of objects with browser, version, and platform information

     */

    @DataProvider(name = "hardCodedBrowsers", parallel = true)

    public static Object[][] sauceBrowserDataProvider(Method testMethod) {

        return new Object[][]{

                new Object[]{"MicrosoftEdge", "14.14393", "Windows 10"},

                new Object[]{"firefox", "49.0", "Windows 10"},

                new Object[]{"internet explorer", "11.0", "Windows 7"},

                new Object[]{"safari", "10.0", "OS X 10.11"},

                new Object[]{"chrome", "54.0", "OS X 10.10"},

                new Object[]{"firefox", "latest-1", "Windows 7"},

        };

    }

public WebDriver driver;

/**

     * @return the {@link WebDriver} for the current thread

     */

    public WebDriver getWebDriver() {

        return webDriver.get();

    }

 /**

    *

    * @return the Sauce Job id for the current thread

    */

   public String getSessionId() {

       return sessionId.get();

   }

/**

 * @throws java.lang.Exception

 */

protected void CreateDriver(String browser, String version, String os, String methodName)

            throws MalformedURLException, UnexpectedException {

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(CapabilityType.BROWSER_NAME, browser);

caps.setCapability(CapabilityType.VERSION,version);

caps.setCapability(CapabilityType.PLATFORM_NAME,os);

caps.setCapability("name",methodName);

 driver = new RemoteWebDriver(new URL(SauceLabURL), caps);

        if (BUILDTAG != null) {

         caps.setCapability("build", BUILDTAG);

        }

        // Launch remote browser and set it as the current thread

        webDriver.set(new RemoteWebDriver(

                new URL("https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"),

                caps));

        // set current sessionId

        String id = ((RemoteWebDriver) getWebDriver()).getSessionId().toString();

        sessionId.set(id);

    }

// Test Results

@AfterMethod(alwaysRun = true)

public void tearDown(ITestResult result) throws Exception {

        ((JavascriptExecutor) webDriver.get()).executeScript("sauce:job-result=" + (result.isSuccess() ? "passed" : "failed"));

        webDriver.get().quit();

    }

    protected void annotate(String text) {

        ((JavascriptExecutor) webDriver.get()).executeScript("sauce:context=" + text);     

}

}

1 Answer

0 votes
by (63.4k points)

It seems you need to set up the saucelab environment variables.

  1. Click Start on the taskbar.

  2. For Search programs and fields, enter Environment Variables.

  3. Click Edit the environment variables. This will open the System Properties dialog.

  4. Click Environment Variables. This will open the Environment Variables dialog.

  5. In the System variables section, click New. This will open the New System Variable dialog.

  6. For Variable name, enter SAUCE_USERNAME.

  7. For Variable value, enter your Sauce username.

  8. Click OK.

  9. Repeat 4 - 8 to set up the SAUCE_ACCESS_KEY.

https://wiki.saucelabs.com/display/DOCS/Best+Practice%3A+Use+Environment+Variables+for+Authentication+Credentials

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...