URGENT : During test execution how to pass Selenium webdriver object to Katalom Web UI?

Hi, I have written a Keyword which launches Android Driver object and executed tests on cloud mobile test platform through Katalon. But I would like use WebUI keywords during the test so I think passing Android Driver object to WebUI driver would help me to achieve this. Could you please help me how to do this or suggest me which is the best way to use WebUI key words along with plain java code in my situation.

Code is below

@Keyword

public static void main() throws MalformedURLException, InterruptedException {

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“app”, “bs://68759ccb92721e210aa81ddbe8f18b74e419990e”);

caps.setCapability(“device”, “Samsung Galaxy S8 Plus”);

caps.setCapability(“browserstack.local”, “true”);

AndroidDriver driver = new AndroidDriver(new URL(“https://”+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=‘No account yet? Create one’]")));

driver.findElement(By.xpath("//*[@text=‘No account yet? Create one’]")).click();

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_name’]")));

driver.findElement(By.xpath("//*[@id=‘input_name’]")).sendKeys(“wrwerwer”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_address’]")));

driver.findElement(By.xpath("//*[@id=‘input_address’]")).sendKeys(“sdasdfasdf”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_email’]")));

driver.findElement(By.xpath("//*[@id=‘input_email’]")).click();

driver.findElement(By.xpath("//*[@id=‘input_email’]")).sendKeys(“asdfsdf”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=‘Already a member? Login’]")));

driver.findElement(By.xpath("//*[@text=‘Already a member? Login’]")).click();

driver.quit();

}

Hari said:

Hi, I have written a Keyword which launches Android Driver object and executed tests on cloud mobile test platform through Katalon. But I would like use WebUI keywords during the test so I think passing Android Driver object to WebUI driver would help me to achieve this. Could you please help me how to do this or suggest me which is the best way to use WebUI key words along with plain java code in my situation.

Code is below

@Keyword

public static void main() throws MalformedURLException, InterruptedException {

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“app”, “bs://68759ccb92721e210aa81ddbe8f18b74e419990e”);

caps.setCapability(“device”, “Samsung Galaxy S8 Plus”);

caps.setCapability(“browserstack.local”, “true”);

AndroidDriver driver = new AndroidDriver(new URL(“https://”+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=‘No account yet? Create one’]")));

driver.findElement(By.xpath("//*[@text=‘No account yet? Create one’]")).click();

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_name’]")));

driver.findElement(By.xpath("//*[@id=‘input_name’]")).sendKeys(“wrwerwer”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_address’]")));

driver.findElement(By.xpath("//*[@id=‘input_address’]")).sendKeys(“sdasdfasdf”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=‘input_email’]")));

driver.findElement(By.xpath("//*[@id=‘input_email’]")).click();

driver.findElement(By.xpath("//*[@id=‘input_email’]")).sendKeys(“asdfsdf”);

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=‘Already a member? Login’]")));

driver.findElement(By.xpath("//*[@text=‘Already a member? Login’]")).click();

driver.quit();

}

WebUI uses different context and it is not the same with Mobile keywords. If your current AUT has webview context, then you can use this keyword: ‘Switch To Web View’ and then use WebUI keywords after that

Hi Vinh, Thanks for the reply.

I think I was wrong with my question. Let me reframe my question.

How to pass runtime Android Driver object to Katalon Mobile object so that with this we should be able to access Katalon mobile inbuilt keywords with Android Driver ( see my code below ). I am asking this as Katalon does not directly support remote Android drivers. ( Example to work with Browserstack navitve apps tests )

I think it should be possible using Katalon api classes. So I am trying to achieve that.

I have reframed my code below

public class testsuite1 { public static DesiredCapabilities caps; public static AndroidDriver driver; @Keyword public static void connectBrowserStack(String appid, String androidcloudurl) throws MalformedURLException, InterruptedException {  caps = new DesiredCapabilities();  caps.setCapability("app", appid);  caps.setCapability("device", "Samsung Galaxy S8 Plus");  caps.setCapability("browserstack.local", "true");  driver = new AndroidDriver(new URL(androidcloudurl), caps); } @Keyword public static void launchApplication() {  new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='No account yet? Create one']")));  driver.findElement(By.xpath("//*[@text='No account yet? Create one']")).click();  driver.findElement(By.xpath("//*[@text='Already a member? Login']")).click(); } @Keyword public static void CloseApplication() {  driver.quit(); }

Hi Vinh, Thanks for the reply. I think I was wrong with my question. Let me reframe my question.

How to pass runtime Android Driver object to Katalon Mobile object so that with this we should be able to access Katalon mobile inbuilt keywords with Android Driver. I am asking this as Katalon does not directly support remote Android drivers. ( Example to work with Browserstack)

I think it should be possible using Katalon api classes. So I am trying to achieve that.

I have reframed my code below

public class testsuite1 {

public static DesiredCapabilities caps;

public static AndroidDriver driver ;

@Keyword

public static void connectBrowserStack(String appid, String androidcloudurl ) throws MalformedURLException, InterruptedException {

caps = new DesiredCapabilities();

caps.setCapability(“app”, appid);

caps.setCapability(“device”, “Samsung Galaxy S8 Plus”);

caps.setCapability(“browserstack.local”, “true”);

driver = new AndroidDriver(new URL(androidcloudurl), caps);

}

@Keyword

public static void launchApplication()

{

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text=‘No account yet? Create one’]")));

driver.findElement(By.xpath("//*[@text=‘No account yet? Create one’]")).click();

driver.findElement(By.xpath("//*[@text=‘Already a member? Login’]")).click();

}

@Keyword

public static void CloseApplication()

{

driver.quit();

}

@“Vinh Nguyen”

Could you please answer for this?

Hi Hari,

Unfortunately Katalon Studio doesn’t have this ability. You can do this for WebDriver, but not for any Mobile Drivers

Regards