2gis / Winium.Mobile

Winium.Mobile is Selenium Remote WebDriver implementation for automated testing of Windows StoreApps and Silverlight apps, tested on emulators (currently only Windows Phone/Mobile apps are supported).
Mozilla Public License 2.0
51 stars 29 forks source link

[WIP] Web context / hybrid apps experiments #165

Open NickAb opened 8 years ago

NickAb commented 8 years ago

WIP. Web context / Hybrid apps support.

NickAb commented 8 years ago

Added Contexts, GetContext, SetContext, GetPageSource (web)

NickAb commented 7 years ago

some samples to see PR in action

import os

from appium.webdriver import Remote
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep

APPX = r"C:\Dev\Winium.StoreApps\Winium\WebViewApp\AppPackages\WebViewApp_1.0.0.0_AnyCPU_Debug_Test\WebViewApp_1.0.0.0_AnyCPU_Debug.appx"
DESIRED_CAPABILITIES = {
    "app": APPX,
    "deviceName": "Emulator 8.1",
    "debugConnectToRunningApp": True
}

class TestPlayground:
    def setup_method(self, _):
        self.driver = Remote(command_executor="http://localhost:9999", desired_capabilities=DESIRED_CAPABILITIES)

    def teardown_method(self, _):
        self.driver.quit()

    @property
    def waiter(self):
        return WebDriverWait(self.driver, timeout=5)

    def test_web_app(self):
        print(self.driver.contexts)
        self.driver.switch_to.context('WEBVIEW_1')
        self.driver.get("http://www.google.com")
        s = self.driver.page_source
        assert len(s) > 0

    def test(self):
        pivots = self.driver.find_elements_by_class_name("Windows.UI.Xaml.Controls.Primitives.PivotHeaderItem")
        pivots[2].click()
        tab = self.driver.find_element_by_id('ThirdTab')
        self.waiter.until(EC.visibility_of(tab))

        print(self.driver.contexts)
        self.driver.switch_to.context('WEBVIEW_1')
        el = self.driver.find_element_by_name('q')
        sleep(1)
        el.click()
        sleep(1)
        #el.send_keys('Hello World!')
        el.send_keys('2^2=')
        sleep(2)
        sbmt = self.driver.find_element_by_xpath('//button[@type="submit"]')
        sbmt.click()
        sleep(5)
NickAb commented 7 years ago

list of commands included in PR