How to retrieve OS, Browser and Screen Resolution of the Machine performing my Test (Suite)?

Hi,

at the beginning of each Katalon Studio log I get some useful information in red letters about the running machine like:

05-17-2018 12:52:33 PM - [RUN_DATA] - Logging run data ‘hostName’ with value ‘myhost’
05-17-2018 12:52:33 PM - [RUN_DATA] - Logging run data ‘os’ with value ‘Windows 10 64bit’
05-17-2018 12:52:33 PM - [RUN_DATA] - Logging run data ‘hostAddress’ with value ‘xxx.xxx.xxx.xxx’
05-17-2018 12:52:33 PM - [RUN_DATA] - Logging run data ‘katalonVersion’ with value ‘5.4.1.1’
[…]
05-17-2018 01:17:21 PM - [RUN_DATA] - Logging run data ‘sessionId’ with value ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’
05-17-2018 01:17:21 PM - [RUN_DATA] - Logging run data ‘browser’ with value ‘Chrome 66.0.3359.181’
05-17-2018 01:17:21 PM - [RUN_DATA] - Logging run data ‘platform’ with value ‘Windows 10’
05-17-2018 01:17:21 PM - [RUN_DATA] - Logging run data ‘seleniumVersion’ with value ‘3.7.1’

From this I conclude that these values are available in any methods, properties or variables during test execution. Besides these I am also interested in the current screen resolution of the executing system, so that in case of an test error on any machine within a Selenium Grid I can send a real-time notification including all relevant information to the responsible product managers.

By the way, I already know the second post in this thread, but this gives me only something like “chrome” instaed of “Chrome 66.0.3359.181”.

Thanks + regards!

1 Like

Hi Drunda

Don’t think you can get all that using WebDriver/Selenium. But you can get some things from JavaScript:

And check this out:

Thanks Russ, once again! :slight_smile: Interesting source, but in fact I wanted preferably something based on Selenium or at least on known and constantly maintained Java classes that I could simply import and update as needed.

I have now created a few simple keywords based on code from various sources, which works very well for my purposes:

package com.mycompany

import regular.stuff.here

import org.openqa.selenium.Capabilities
import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.RemoteWebDriver
import com.kms.katalon.core.webui.driver.DriverFactory
import java.awt.*

public class GetTestingConfig {
    @Keyword
    def getOperatingSystem () {
        println System.getProperty('os.name')
    }

    @Keyword
    def getBrowserAndVersion() {
        WebDriver driver = DriverFactory.getWebDriver()
        Capabilities caps = ((RemoteWebDriver) driver).getCapabilities()
        String browserName = caps.getBrowserName().capitalize()
        String browserVersion = caps.getVersion()
        println browserName + ' ' + browserVersion
    }

    @Keyword
    def getScreenResolution() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize()
        Integer screenHeight = screenSize.height
        Integer screenWidth = screenSize.width
        println screenWidth + 'x' + screenHeight
    }
}

Hope it will also help others.

Regards

7 Likes

Upvoted - cool. Me like. B)

Shame you can’t “Best Answer” your own post :frowning:

Thanks, the praise of you ennobles me enough :slight_smile:

My Two Cents … The below keyword, will provide the below details:

Selenium Automation Script run by Local Host Name/IP Address: USERNAME/10.123.45.67

Name of the OS : Windows 7

Version of the OS : 6.1

Architecture of the OS : amd64

Name of the Browser : chrome

Browser Version : 66.0.3359.181

import org.openqa.selenium.Capabilities;import org.openqa.selenium.WebDriverimport org.openqa.selenium.remote.RemoteWebDriver;import com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.webui.driver.DriverFactorypublic class Host {	static WebDriver driver = DriverFactory.getWebDriver()	@Keyword	public static String details() {		try {			//Get Browser name and version.			Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();			String browserName =    "Name of the Browser    : " +caps.getBrowserName()+ "\n";			String browserVersion = "Browser Version        : " +caps.getVersion();			java.net.InetAddress i = java.net.InetAddress.getLocalHost();			String convertedToString = String.valueOf(i);			convertedToString = "Selenium Automation Script run by Local Host Name/IP Address: " + i+ "\n";			String details = "Name of the OS         : " + System.getProperty("os.name") + "\n" + "Version of the OS      : " + System.getProperty("os.version") + "\n" + "Architecture of the OS : " + System.getProperty("os.arch")+ "\n";			return convertedToString+details+browserName+browserVersion;		} catch (Exception e) {			e.printStackTrace();		}		String x = "Unknown";		return x;	}
}
2 Likes

Thank you, discover.selenium, but:

Please note, the os.arch property will only give you the architecture of the JRE, not of the underlying os.

Look here for details: https://stackoverflow.com/questions/1856565/how-do-you-determine-32-or-64-bit-architecture-of-windows-using-java

I am just getting started trying to run keywords like these. Do you do anything unique in the setup of the keywords?