Guru raj sharma
Guru raj sharma

Reputation: 1

Safari Not working in sauce labs free-tier for web automation using selenium

I am using free-tier and unable to perform test automation using selenium on safari and edge (even though i am using the desired capabilities from the platform configurator) . Sometimes it says:

session not created

And other times it says:

unsupported OS or browser combination

Even though configuration is selected from the platform configurator. My questions are:

1.Is it because of the free-tier?

2.If not,please help me with the latest java code for safari configuration

testng.xml:

    <test thread-count="5" name="Safari Test">
    <parameter name="browser" value="safari"></parameter>
    <parameter name="platform" value="macOS 10.15"></parameter>
    <parameter name="version" value="latest"></parameter>
    <classes>
        <class name="com.demo.saucelabs.SaucelabsDemo" />
    </classes>
</test> 

java class:

    MutableCapabilities sauceOptions = new MutableCapabilities();
    sauceOptions.setCapability("name", name.getName());
    sauceOptions.setCapability("build", "saucelabs demo");
    sauceOptions.setCapability("seleniumVersion", "3.141.59");
    sauceOptions.setCapability("username", USER_NAME);
    sauceOptions.setCapability("accessKey", ACCESS_KEY);
    
    
    MutableCapabilities capabilities = new MutableCapabilities();
    if (browser.equals("chrome")) {
        ChromeOptions caps = new ChromeOptions();
        caps.setExperimentalOption("w3c", true);
        capabilities = caps;
    }
    else if (browser.equals("firefox")) {
        capabilities = new FirefoxOptions();
    }
    else if (browser.equals("safari")) {
        capabilities = new SafariOptions();
    }
    else if (browser.toLowerCase().equals("microsoftedge")) {
        capabilities = new EdgeOptions();
    }
    capabilities.setCapability("sauce:options", sauceOptions);
    capabilities.setCapability("browserVersion", version);
    capabilities.setCapability("platformName", platform);   
    capabilities.setCapability("browserName", browser);

    try {
        driver = new RemoteWebDriver(new URL(SAUCELABS_URL), capabilities);
    } catch (Exception e) {
        e.printStackTrace();
    }

Upvotes: 0

Views: 416

Answers (1)

joshin4colours
joshin4colours

Reputation: 1696

Using Safari on a free-tier or free trial from Sauce Labs should still work, all browser platforms should be available to you.

I also ran a test with the following configuration and it worked:

MutableCapabilities sauceOptions = new MutableCapabilities();

SafariOptions browserOptions = new SafariOptions();
browserOptions.setCapability("platformName", "macOS 10.15");
browserOptions.setCapability("browserVersion", "latest");
browserOptions.setCapability("sauce:options", sauceOptions);

which is from the platform configurator. I would try this out first, then add the sauce:options as needed.

Upvotes: 1

Related Questions