Skip to main content
Experience faster, smarter testing with BrowserStack AI Agents. See what your workflow’s been missing. Explore now!
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Identify Current Browser Instance in Automate

At runtime, how do I identify the browser instance for which the session is running?

You can now fetch the device OS details at the run-time for the current test session. You need to call getCurrentPlatform function, which will return the device OS details as declared in the yml file in a readable format. You can then manipulate the returned data object to perform specific device manipulations.

package com.browserstack;
import org.junit.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import com.browserstack.BrowserStackSdk;
import static org.junit.Assert.assertTrue;
public class BStackLocalTest extends BrowserStackJUnitTest {
    @Test
    public void test() {
        System.out.println(BrowserStackSdk.getCurrentPlatform());
        driver.get("http://bs-local.com:45454/");
        assertTrue("Local content not validated!", driver.getTitle().contains("BrowserStack Local"));
    }
}

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle