How to open a new Chrome’s tab? A detail example would be much appreciated!


#1

Hi there,

I would like to open a new browser tab by Katalon? Could you please give a detail instruction?

Thanks,

Serena.

 


#2

Thanks much!


#3

Hi there,

You can press ‘Ctrl + T’ key to open new tab in Chrome by using ‘Send Key’ action:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(‘www.google.com’)

WebUI.sendKeys(findTestObject(null), Keys.chord(Keys.CONTROL + ‘t’))


#4

For me it doesn’t open a new tab, although the test case succeded.
it says:
Keys ‘CONTROL + t’ sent to object: ‘tempBody’


#5

For me it didn’t work as well. The problem is with using the WebUI for sending the keys… It doesn’t actually send the keys.
One way of fixing it is using the java.awt.Robot library:

https://docs.oracle.com/javase/7/docs/api/index.html?java/awt/Robot.html
https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#mouseMove(int,%20int)

Here is an example code:

import java.awt.Robot as Robot
import java.awt.event.KeyEvent as KeyEvent

Robot robot = new Robot()
robot.keyPress(KeyEvent.VK_CONTROL)
robot.keyPress(KeyEvent.VK_T)
robot.keyRelease(KeyEvent.VK_CONTROL)
robot.keyRelease(KeyEvent.VK_T)