"Browser is not opened" error on trying to switch to webview from Mobile application

i want to switch to webview from mobile application , perform some actions and switch back to Mobile app again . i am using “switchToWebView” and using webUI commands , but getting BrowserNotOpenedException: Browser is not opened.

=============== ROOT CAUSE =====================

Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html

================================================

10-16-2023 07:14:40 PM scrollToPosition(100, 200)

Elapsed time: 0.172s

Unable to scroll to position x = 100, y = 200 (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to scroll to position x = 100, y = 200

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword.scrollToPosition(ScrollToPositionKeyword.groovy:85)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword.execute(ScrollToPositionKeyword.groovy:68)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.scrollToPosition(WebUiBuiltInKeywords.groovy:4495)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$scrollToPosition.call(Unknown Source)

at Invoices_PaymentFlow_Stripe.run(Invoices_PaymentFlow_Stripe:162)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1697463564725.run(TempTestCase1697463564725.groovy:25)

Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened

Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’

System info: host: ‘pruthvis-MacBook-Pro.local’, ip: ‘10.6.0.138’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘13.6’, java.version: ‘1.8.0_362’

Driver info: driver.version: unknown

at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriverIsOpen(DriverFactory.java:1003)

at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriver(DriverFactory.java:988)

at com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver(DriverFactory.java:974)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword$_scrollToPosition_closure1.doCall(ScrollToPositionKeyword.groovy:83)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword$_scrollToPosition_closure1.call(ScrollToPositionKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword.scrollToPosition(ScrollToPositionKeyword.groovy:85)

at com.kms.katalon.core.webui.keyword.builtin.ScrollToPositionKeyword.execute(ScrollToPositionKeyword.groovy:68)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.scrollToPosition(WebUiBuiltInKeywords.groovy:4495)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$scrollToPosition.call(Unknown Source)

at Script1697263725229.run(Script1697263725229.groovy:162)

… 11 more

)

Please update browser from katalon and try again

@pruthvi.gowda
correct me if I’m wrong

  1. you are trying to switch from a mobile application to a web Application on your pc?
    or
  2. you are trying to switch from the mobile browser to the mobile native application?

if your case is 1
you have to use the following

  1. specify the driver
  2. change the Driver in the DriverFactory
  3. you can use the Katalon WebUI Keywords
String driverpath=System.getProperty('user.dir')+"\\WebDriver\\chromedriver.exe"

System.setProperty('webdriver.chrome.driver', driverpath)

WebDriver driver = new ChromeDriver()

DriverFactory.changeWebDriver(driver)

driver.manage().window().maximize()

driver.get(GlobalVariable.appUrl)

Hi ,
I am trying to switch from Native mobile application on Android device to mobile browser .
Flow is something like.

  1. Copy url from mobile application
    2.open with chrome
  2. Do some web actions
    4.switch back to mobile application

hi @pruthvi.gowda

switchToWebView only looks for webviews inside the app you started, chrome is a different process so there is nothing to switch to, hence the browser not opened error.

appium does expose chrome tabs as a context once chrome is in the foreground. so the flow becomes:

def d = MobileDriverFactory.getDriver()
d.executeScript('mobile: deepLink', [url: copiedUrl, package: 'com.android.chrome'])
Mobile.delay(3)
println d.getContextHandles()  // expect WEBVIEW_chrome
d.context('WEBVIEW_chrome')
// WebUI keywords now run against the chrome tab
WebUI.click(findTestObject('web/btn_pay'))
d.context('NATIVE_APP')
d.executeScript('mobile: activateApp', [appId: 'com.your.app'])

for this to work appium needs a chromedriver matching the chrome version on the device, chromedriverAutodownload in the server args or chromedriverExecutable in desired capabilities. if WEBVIEW_chrome never shows up, the chromedriver mismatch is almost always why. this is my read of it on uiautomator2, i have done the same with a webview app rather than chrome itself, but the context mechanism is identical.

WebUI keywords use Katalon’s own web driver reference, not the Appium driver, so after d.context('WEBVIEW_chrome') they can still throw “Browser is not opened”. Point Katalon at it first:

import com.kms.katalon.core.webui.driver.DriverFactory
DriverFactory.changeWebDriver(d)

A few other things:

  1. Replace the fixed Mobile.delay(3) with a loop that polls d.getContextHandles() until the Chrome context appears.
  2. Chrome may have several tabs open. Use d.getWindowHandles() or WebUI.switchToWindowUrl to land on the right one.
  3. Don’t call WebUI.closeBrowser() on this driver, since it would likely end the Appium session. Just switch back to NATIVE_APP and activate your app.
  4. Log getContextHandles() the first time, because the context name can differ (e.g. CHROMIUM vs WEBVIEW_chrome) depending on how Chrome was launched.