Exemplo n.º 1
0
def evaluate_js():
    child_window = webview.create_window('Window #2', 'https://google.com')
    assert child_window != 'MainWindow'
    result1 = webview.evaluate_js("""
        document.body.style.backgroundColor = '#212121';
        // comment
        function test() {
            return 2 + 5;
        }
        test();
    """)

    assert result1 == 7

    result2 = webview.evaluate_js("""
        document.body.style.backgroundColor = '#212121';
        // comment
        function test() {
            return 2 + 2;
        }
        test();
    """,
                                  uid=child_window)
    assert result2 == 4
    webview.destroy_window(child_window)
Exemplo n.º 2
0
def on_message(ws, message):
    """ The screen react to MOVE and SHOW messages only"""
    try:
        pkg = json.loads(message)
    except Exception:
        return ws.send(
            msg.create_error_pkg(u'Format error'))
    if pkg['TYPE'] == msg.MOVE:
        # MOVE THE screen
        pass
    if pkg['TYPE'] == msg.SHOW:
        time.sleep(pkg['delay_s'])
        webview.load_url(pkg['url'])
        webview.evaluate_js(
        """
        if (window.hasOwnProperty('Reveal')) {
            Reveal.addEventListener( 'slidechanged', function( event ) {
                if(Reveal.isLastSlide()){
                    pywebview.api.shown()
                }
            } )
        };
        """
        )
    # else:
    #     print(
    #         msg.create_error_pkg(u'Unknown TYPE'))
    print(message)
Exemplo n.º 3
0
def setRingQ(row, col, q, color):
    webview.evaluate_js("""
    (function() {{
        var lights = document.querySelectorAll('.row-{row}.col-{col} circle.q-{q}');
        for (let light of lights) {{
            light.setAttributeNS(null, 'fill', '{color}');
        }}
    }})()
    """.format(row=row, col=col, q=q, color=getColor(color)))
Exemplo n.º 4
0
def setAllRings(color):
    webview.evaluate_js("""
    (function() {{
        var lights = document.querySelectorAll('circle');
        for (let light of lights) {{
            light.setAttributeNS(null, 'fill', '{color}');
        }}
    }})()
    """.format(color=getColor(color)))
Exemplo n.º 5
0
def assert_func():
    sleep(1)
    html_result = webview.evaluate_js('document.getElementById("heading").innerText')
    assert html_result == 'Hello there!'

    css_result = webview.evaluate_js('window.getComputedStyle(document.body, null).getPropertyValue("background-color")')
    assert css_result == 'rgb(255, 0, 0)'

    js_result = webview.evaluate_js('window.testResult')
    assert js_result == 80085

    assert_js(webview, 'test', 'JS Api is working too')
Exemplo n.º 6
0
    def signUp(self, trash=0):  # Функция регистрации и входа в личный кабинет
        login = self.storage.pop()
        password = self.storage.pop()
        name = self.storage.pop()
        surname = self.storage.pop()

        result = self.connect.sign_up(login, password, name, surname)
        time.sleep(1)
        if result.get('error') is None:
            webview.evaluate_js("set_window_office();")
            webview.evaluate_js(
                "set_office_name('Имя: ' + '%s', 'Фамилия: ' + '%s');" %
                (name, surname))
Exemplo n.º 7
0
 def set_store(self, trash=0):
     # 6)add_coordinate(координата_x, координата_y, цена(не обязательно)), возвращает  {'value': получилось_ли}
     # вернет нет  если  тебя нет в игре, игра еще не началась или ты на этом раунде уже  ставил магазин
     x = self.storage.pop()
     y = self.storage.pop()
     cost = self.storage.pop()
     print(x, y, cost)
     result = self.connect.add_coordinate(x, y, cost)
     if result.get('value'):
         webview.evaluate_js("""set_store(%s, %s""" %
                             (x, y))  # TODO set_store func js
     else:
         # TODO вывести сообщение "если  тебя нет в игре, игра еще не началась или ты на этом раунде уже  ставил магазин"
         pass
Exemplo n.º 8
0
def assert_func():
    sleep(1)
    html_result = webview.evaluate_js(
        'document.getElementById("heading").innerText')
    assert html_result == 'Hello there!'

    css_result = webview.evaluate_js(
        'window.getComputedStyle(document.body, null).getPropertyValue("background-color")'
    )
    assert css_result == 'rgb(255, 0, 0)'

    js_result = webview.evaluate_js('window.testResult')
    assert js_result == 80085

    assert_js(webview, 'test', 'JS Api is working too')
Exemplo n.º 9
0
 def signIn(self, trash=0):  # Функция входа в личный кабинет
     login = self.storage.pop()
     print(login)
     password = self.storage.pop()
     print(login, password)
     result = self.connect.sign_in(login, password)
     print(result)
     time.sleep(1)
     if result.get('error') is None:
         webview.evaluate_js("set_window_office();")
         name = result.get('name', '')
         surname = result.get('family', '')
         webview.evaluate_js(
             "set_office_name('Имя: ' + '%s', 'Фамилия: ' + '%s');" %
             (name, surname))
Exemplo n.º 10
0
def array_test():
    result = webview.evaluate_js("""
    function getValue() {
        return [undefined, 1, 'two', 3.00001, {four: true}]
    }
    getValue()
    """)
    assert result == [None, 1, 'two', 3.00001, {'four': True}]
Exemplo n.º 11
0
def string_test():
    result = webview.evaluate_js("""
    function getValue() {
        return "this is only a test"
    }

    getValue()
    """)
    assert result == u'this is only a test'
Exemplo n.º 12
0
def int_test():
    result = webview.evaluate_js("""
    function getValue() {
        return 23
    }

    getValue()
    """)
    assert result == 23
Exemplo n.º 13
0
def nan_test():
    result = webview.evaluate_js("""
    function getValue() {
        return NaN
    }

    getValue()
    """)
    assert result is None
Exemplo n.º 14
0
def object_test():
    result = webview.evaluate_js("""
    function getValue() {
        return {1: 2, 'test': true, obj: {2: false, 3: 3.1}}
    }

    getValue()
    """)
    assert result == {'1': 2, 'test': True, 'obj': {'2': False, '3': 3.1}}
Exemplo n.º 15
0
def int_test():
    result = webview.evaluate_js("""
    function getValue() {
        return 23
    }

    getValue()
    """)
    assert result == 23
Exemplo n.º 16
0
def object_test():
    result = webview.evaluate_js("""
    function getValue() {
        return {1: 2, 'test': true, obj: {2: false, 3: 3.1}}
    }

    getValue()
    """)
    assert result == {'1': 2, 'test': True, 'obj': {'2': False, '3': 3.1}}
Exemplo n.º 17
0
def undefined_test():
    result = webview.evaluate_js("""
    function getValue() {
        return undefined
    }

    getValue()
    """)
    assert result is None
Exemplo n.º 18
0
def nan_test():
    result = webview.evaluate_js("""
    function getValue() {
        return NaN
    }

    getValue()
    """)
    assert result is None
Exemplo n.º 19
0
def string_test():
    result = webview.evaluate_js("""
    function getValue() {
        return "this is only a test"
    }

    getValue()
    """)
    assert result == u'this is only a test'
Exemplo n.º 20
0
def undefined_test():
    result = webview.evaluate_js("""
    function getValue() {
        return undefined
    }

    getValue()
    """)
    assert result is None
Exemplo n.º 21
0
 def _evaluate_js(webview):
     result = webview.evaluate_js("""
         document.body.style.backgroundColor = '#212121';
         // comment
         function test() {
             return 2 + 2;
         }
         test();
     """)
     assert result == 4
Exemplo n.º 22
0
def mixed_test():
    result = webview.evaluate_js("""
        document.body.style.backgroundColor = '#212121';
        // comment
        function test() {
            return 2 + 2;
        }
        test();
    """)
    assert result == 4
Exemplo n.º 23
0
def evaluate_js():
    # Change document background color and print document title
    print(
        webview.evaluate_js("""
        // Turn night mode ON
        document.body.style.backgroundColor = '#212121';
        document.body.style.color = '#f2f2f2';

        // Return document title
        document.title;
        """))
Exemplo n.º 24
0
def evaluate_js():
    child_window = webview.create_window('Window #2', 'https://google.com')
    assert child_window != 'MainWindow'
    result1 = webview.evaluate_js("""
        document.body.style.backgroundColor = '#212121';
        // comment
        function test() {
            return 2 + 5;
        }
        test();
    """)

    assert result1 == 7

    result2 = webview.evaluate_js("""
        document.body.style.backgroundColor = '#212121';
        // comment
        function test() {
            return 2 + 2;
        }
        test();
    """, uid=child_window)
    assert result2 == 4
    webview.destroy_window(child_window)
Exemplo n.º 25
0
def evaluate_js():
    result = webview.evaluate_js(
        r"""
        var h1 = document.createElement('h1')
        var text = document.createTextNode('Hello pywebview')
        h1.appendChild(text)
        document.body.appendChild(h1)
               
        document.body.style.backgroundColor = '#212121'
        document.body.style.color = '#f2f2f2'
        
        // Return user agent
        'User agent:\n' + navigator.userAgent;
        """
    )

    print(result)
Exemplo n.º 26
0
    def get_cookies():
        timeout = 120

        def is_logged_in():
            return webview.evaluate_js(
                "document.querySelector('#logout-btn') !== null")

        while not webview.webview_ready() or not is_logged_in():
            time.sleep(1)
            timeout -= 1
            if timeout == 0:
                raise AuthenticationFailed("Can't login, timeout exceeded.")
            if not webview.window_exists():
                raise AuthenticationFailed(
                    "Webview window closed prematurely.")

        cookies = webview.evaluate_js("document.cookie")
        webview.destroy_window()
        return cookies
Exemplo n.º 27
0
Arquivo: autosms.py Projeto: Rgz7/code
	def on_press(self,key):
		webview.evaluate_js('''document.getElementById("keypress").innerHTML = "{}" '''.format(key))
		
		if (key == Key.esc):
			if (self.actionCheck == "GetBrowserPosition"):
				self.position["GetBrowserPosition"] = self.record
				webview.evaluate_js('''document.getElementById("browserTag").innerHTML = "{}" '''.format(self.record))
				self.record = []
			elif (self.actionCheck == "GetPhoneNumberPosition"):
				self.position["GetPhoneNumberPosition"] = self.record
				webview.evaluate_js('''document.getElementById("phoneNumberPosition").innerHTML = "{}" '''.format(self.record))
				self.record = []
			elif (self.actionCheck == "GetSendPosition"):
				self.position["GetSendPosition"] = self.record
				webview.evaluate_js('''document.getElementById("sendSMS").innerHTML = "{}" '''.format(self.record))
				self.record = []
			else :
				pass 
			print(self.position)
			return False
			
		self.record.append(mygui.position())
		print(mygui.position())
Exemplo n.º 28
0
def evaluate_js():
    webview.evaluate_js('document.documentElement.style.zoom = 1.0')
Exemplo n.º 29
0
def evaluate_js():
    import time
    time.sleep(2)

    # Change document background color and print document title
    print(webview.evaluate_js("(function(){var a=123;alert(a)})()"))
Exemplo n.º 30
0
 def join_the_game(
         self,
         trash=0):  # здесь открывается окно с картой и начинается игра
     webview.evaluate_js("set_window_map();")
Exemplo n.º 31
0
 def active_office_button(
     self,
     trash=0
 ):  # Функция вызывается, когда начинается игра(кнопка становится видимой)
     webview.evaluate_js("set_button_active();")
Exemplo n.º 32
0
 def set_cell_info(self, x, y, population, transport_transactions,
                   current_min_cost, contribution_of_stores):
     webview.evaluate_js("""
                         set_cell_info(%s, %s, %s, %s, %s, %s);
                         """ % (x, y, population, transport_transactions,
                                current_min_cost, contribution_of_stores))
Exemplo n.º 33
0
 def set_current_round(self, num):
     webview.evaluate_js("set_round(%s);" % num)
Exemplo n.º 34
0
 def set_player_info(self, number_id, firstname, lastname, gain):
     webview.evaluate_js("""
                         set_player_info(%s, %s, %s, %s);
                         """ % (number_id, firstname, lastname, gain))
Exemplo n.º 35
0
 def assertFunction(func_name, result):
     webview.evaluate_js(js_code.format(func_name))
     sleep(2.0)
     assert webview.evaluate_js('window.pywebviewResult') == result
Exemplo n.º 36
0
def load_html():
    webview.load_html("<h1>This is dynamically loaded HTML</h1>")
    webview.evaluate_js('alert("w00t")')
Exemplo n.º 37
0
def load_html():
    webview.load_url("http://www.baidu.com")
    print(123123)
    time.sleep(2)
    webview.evaluate_js('alert("w00t")')
    print(2222)
Exemplo n.º 38
0
 def signIn(self, trash=0):
     webview.evaluate_js("""set_window_menu();""")