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 org.openqa.selenium.chrome.ChromeDriver
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();
@Keyword
def Login(String url, String login, String pw){
driver.manage().window().maximize();
driver.get(url);
driver.findElement(By.name("username")).sendKeys(login);
driver.findElement(By.name("password")).sendKeys(pw);
driver.findElement(By.xpath("//button[contains(text(), 'Connexion')]")).click();
}
@Keyword
def Lougout(){
//Thread.sleep(2000);
driver.findElement(By.xpath("//span[@id='HEADER_USER_MENU_POPUP_text']")).click();
driver.findElement(By.xpath("//td[@id='HEADER_USER_MENU_LOGOUT_text']")).click();
driver.quit();
}
}
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.
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.