Use same instance of browser for multiple Custom Keywords

Hi, I’m trying to run Custom Keywords with same instance of browser like/in test cases, but on second keyword (Logout) it open a new browser window.
The code look like this

package kayword

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebU

public class Manuel {
	WebDriver driver = new ChromeDriver();

	def Login(String url, String login, String pw){
		driver.findElement(By.xpath("//button[contains(text(), 'Connexion')]")).click();
	def Lougout(){

Thanks in advance

Your code shows a class with two methods.

Where is the test case that uses the two methods? Can you post that as well?

I’m just calling the 2 keywords in test cases

Your class Manual has a line new ChromeDriver(). This is not good. This line is called when your test case calls CustomKeywords.'classname.Logout'(). You should move this line out of the Keyword class, and instead write it in you test case script.

And you should modify the method signature of your Keyword class so that it accepts WebDriver instance as argument from Test Case.

    def Login(WebDriver driver, String url, String login, String pw) {
    def Logout(WebDriver driver) {

But if I add (WebDriver driver) as parameter, what it should be value type /

Sorry, I do not see what the ‘Input’ screen of which screenshot you attached.

I never use the Manual mode of Test Case editor, I always use the Script mode.

Here’s how it look like in script

but I didn’t understood what do you mean by

new ChromeDriver() . This is not good. This line is called when your test case calls CustomKeywords.'classname.Logout'() . You should move this line out of the Keyword class, and instead write it in you test case script.

Try this.

The Keyword class:

package kaywords

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver

public class Keyword {

	def login(WebDriver driver, String url, String login, String pw) {
		driver.findElement(By.xpath("//button[contains(text(), 'Login')]")).click();

	def logout(WebDriver driver) {

The Test Case script:

import org.openqa.selenium.WebDriver

import com.kms.katalon.core.webui.driver.DriverFactory

String chromeDriverPath = DriverFactory.getChromeDriverPath()
System.setProperty('', chromeDriverPath)

WebDriver driver = new ChromeDriver()

		'John Doe',

// or similarly
//new kaywords.Keyword().logout(driver)

Thank you it works like charm