2

I am testing an Android Phone application which is based on Hybrid Application Canvas, most of the functionalities i have to test are Canvas based and only way i have is to use JavaScript to be called from Python Scripts.

Before executing Javascript, I convert Phones Native View to Web View by using set Contexts

def set_current_context(self, num_ctx):
        self.driver.switch_to.context(self.driver.contexts[int(num_ctx)])

def set_serial(self, android_serial):
        desired_caps = self.getDevice(android_serial)
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        return self.driver

Basic JavaScripts like "document.title" or "window.xyz" works fine and performs certain action.

Now; If i want to fetch page information (Which previously was done using nightwatch)

this.browser.page.YourPage(); // Nightwatch javascript

but if i directly send above command i get error JavascriptException: Message: javascript error: Cannot read property 'page' of undefined

def direct_script(self, script, *args):
        print(script, *args)
        self.driver.execute_script("$(document).ready (function (){ this.browser.page.YourPage() });", *args)

Manually i checked from console of the browser where this.browser returned undefined.

So in my opinion i think there should be some way to pass browser instance on which i can run commands.

Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21

1 Answers1

3

They're different contexts. this.browser isn't available. You'll need to do whatever page.YourPage(); is trying to do via the driver or via execute_script.

Jess
  • 3,097
  • 2
  • 16
  • 42