def tearDown(self): if self.objPython != list(asSeq(self.ctx.globalObject.objJS)): self.fail("Python object %s differs from JavaScript object %s" % \ (repr(self.objPython), repr(list(self.ctx.globalObject.objJS)))) TestCaseWithContext.tearDown(self)
def load_finished_cb(self, view, frame): print "load_finished" # Retrieve the JavaScript context from the browser widget. ctx = jscore.JSContext(self.webView.get_main_frame().get_global_context()) # Retrieve the JavaScript window object. window = ctx.globalObject.window # Alert works! #window.alert("This is an alert") # We can change properties in the window object. window.foo = 'bar' assert ctx.evaluateScript("window.foo") == 'bar' # Retrieve the DOM document object. document = ctx.globalObject.document # Document title. print "Title:", document.title form = document.forms[0] # List all A (anchor) tags. atags = document.getElementsByTagName("a") print atags.__class__.__name__ print list(atags.iterkeys()) for a in jscore.asSeq(atags): print a.href
def load_finished_cb(self, view, frame): print "load_finished" # Retrieve the JavaScript context from the browser widget. ctx = jscore.JSContext(self.webView.get_main_frame().get_global_context()) # Retrieve the JavaScript window object. window = ctx.globalObject.window # Alert works! # window.alert("This is an alert") # We can change properties in the window object. window.foo = "bar" assert ctx.evaluateScript("window.foo") == "bar" # Retrieve the DOM document object. document = ctx.globalObject.document # Document title. print "Title:", document.title form = document.forms[0] # List all A (anchor) tags. atags = document.getElementsByTagName("a") print atags.__class__.__name__ print list(atags.iterkeys()) for a in jscore.asSeq(atags): print a.href
def testContains4(self): obj = asSeq(self.ctx.evaluateScript(""" (['a', 'b', 'c', 'd', 'e']) """)) self.assertTrue('a' in obj) self.assertTrue('c' in obj) self.assertTrue('e' in obj) self.assertFalse('f' in obj) self.assertFalse(1 in obj) self.assertFalse(None in obj)
def testContains4(self): obj = asSeq( self.ctx.evaluateScript(""" (['a', 'b', 'c', 'd', 'e']) """)) self.assertTrue('a' in obj) self.assertTrue('c' in obj) self.assertTrue('e' in obj) self.assertFalse('f' in obj) self.assertFalse(1 in obj) self.assertFalse(None in obj)
def testIter1(self): self.ctx.evaluateScript(""" i = 0; props = []; for (prop in objPython) { if (objPython.hasOwnProperty(prop)) { props[i] = prop; } i++; }""") self.assertEqual(sorted(self.objPython), sorted(asSeq(self.ctx.globalObject.props)))
def setUp(self): TestCaseWithContext.setUp(self) self.obj = asSeq( self.ctx.evaluateScript(""" ([1, 2, 3, 4, 5]) """))
def testContains5(self): obj = asSeq(self.ctx.evaluateScript("""[]""")) self.assertFalse('f' in obj) self.assertFalse(1 in obj) self.assertFalse(None in obj)
def testAsSeq2(self): self.assertEqual(self.obj.length, 5) asSeq(self.obj).append(6) self.assertEqual(self.obj.length, 6)
def testAsSeq1(self): s1 = asSeq(self.obj) s2 = asSeq(self.obj) self.assertTrue(s1 is s2)
def setUp(self): TestCaseWithContext.setUp(self) self.obj = asSeq(self.ctx.evaluateScript(""" ([1, 2, 3, 4, 5]) """))