Selenium Test Script example?

So I’m trying a new method of writing some test scripts… instead of Katalon scripts…

but everytime I start this test… chrome opens up twice…
first it opens on google.com as I want it to be…instead of going to the “whatever.com” site, it opens another chrome instance and uses that… so I’m left with an extra chrome browser.

Is there anything I’m doing wrong?

This is my script.

import org.openqa.selenium.By
import org.openqa.selenium.Dimension
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser("https://www.google.com")
WebDriver driver = new ChromeDriver()

driver.get("https://whatever.com");
driver.manage().window().setSize(new Dimension(1692, 1087));

Yes, your script will open browser 2 twice.

1st by

WebUI.openBrowser("https://www.google.com")

2nd by

WebDriver driver = new ChromeDriver()

if i dont use WebUI.open then it fails the test lol

what’s the right codeblock for the above so it opens and goes to the site i want?

It’s asking to set sytem property - i guess that’s the path of the chromedriver… but i’ve seen others do it without that… confused

I don’t see what you mean. Show your code and the error log you got.

If you want to achieve what you stated above, then you want to avoid WebUI.openBrowser(...), don’t you?

No. Your perception is wrong.

Anybody who works on the pure Selenium WebDriver API without Katalon stuff does set system property with the path of chromedriver. Otherwise their script wouldn’t work.

If you want to be “Katalon free”, then you must find out how to set system property with the path of chromedriver.

You have an option:

  1. Download the Chrome Driver executable from the download site, locate it into a folder of your choice. Then set the path of the folder to the system property as documented. This way you can completely be free from Katalon “WebUI” API.

  2. Reuse the Chrome Driver executable which is bundled in Katalon Studio. You can inquire the path of the executable by DriverFactory (Katalon Studio API Specification). This way, you can NOT be free from Katalon API.

I personally use GitHub - bonigarcia/webdrivermanager: Automated driver management and other helper features for Selenium WebDriver in Java, which helps resolving dependency to WebDriver executables.

You have got a sufficient advice in the error message:

The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see ChromeDriver · SeleniumHQ/selenium Wiki · GitHub.

Why not you do that?

An alternative

import com.kms.katalon.core.webui.driver.DriverFactory
...
WebUI.openBrowser("https://www.google.com")
WebDriver driver = DriverFactory.getWebDriver()
...

This will open a single Browser window, will reuse that window to continue.

This way you would use the WebDriver executable bundled in Katalon Studio while the system property is properly configured by Katalon. Thanks to Katalon!

https://api-docs.katalon.com/com/kms/katalon/core/webui/driver/DriverFactory.html#getWebDriver()

Please note, in this way, you would not be free from Katalon API. Does it matter?

Yea, this is the way i was trying to set it up… I did that one line wrong. i think this will work fine.

I coudln’t invoke chromedriver on my machine because of some corporate security block… which I could have requested to be removed but rather avoid that path.

thanks! this seems like the solution!

I’m afraid, your primary issue “to be Katalon free” won’t be achieved yet.

yea… I get what you’re saying. I mean all our tests now is katalon-dependent… the way we coded it. if kataon shuts down or we choose to move to another platform, we are kind of screwed.

I guess you’re right, I’d have to use this method instead: System.setProperty(“webdriver.chrome.driver”,“C:/Users/chromedriver.exe”);

^ does that look right? I think it is cuz I’m getting that security block message lol

I don’t know.

I don’t see what “security block” is.

Did you really tried this?

If yes, …

How careless you are!

You don’t respect the security practice in the Windows’ file system at all.

Yes, you should be blocked!

Why not you take a safer way, like
“C:/Users/asharafmadina/webdrivers/chromedriver.exe”