diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5df8e96..812735d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,6 +1,13 @@ name: publish-docs on: + push: + paths: + - "docs/**" + pull_request: + paths: + - "docs/**" + workflow_call: inputs: deploy: @@ -25,17 +32,17 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + - name: Checkout-检出项目 + uses: actions/checkout@v4 + + - name: Env Setup + uses: ./.github/actions/env_setup - - uses: actions/cache@v3 - with: - key: mkdocs-material-${{env.cache_id}} - path: .cache - restore-keys: - mkdocs-material- - - run: pip install mkdocs-material - - run: mkdocs gh-deploy --force + - name: Build-生成文档 + run: | + poetry run mkdocs build + + - name: Deploy-部署文档 + if: github.event.inputs.deploy == true + run: | + poetry run mkdocs gh-deploy --force \ No newline at end of file diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index c0c1e0e..5c35595 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -11,6 +11,12 @@ name: Upload Python Package on: release: types: [published] + workflow_dispatch: + inputs: + version: + description: 'Version' + type: string + required: true jobs: test: @@ -21,24 +27,26 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - + - name: Env Setup + uses: ./.github/actions/env_setup + + - name: 将Tag版本号填写到toml配置中 + if: github.event.release.tag_name + run: poetry version ${{github.event.release.tag_name}} + - name: 将version参数更新到toml配置中 + if: github.event.inputs.version + run: poetry version ${{github.event.inputs.version}} + + - name: Install dependencies + run: | + poetry install + - name: Build package + run: poetry build + - name: Publish package + run: | + poetry publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} + docs: needs: [ deploy ] uses: ./.github/workflows/docs.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aec268a..19a3c4c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,10 +22,33 @@ jobs: test-android: runs-on: windows-latest + + services: + avd: + image: budtmo/docker-android:emulator_11.0 + ports: + - 6080:6080 + - 5554:5554 + - 5555:5555 + env: + EMULATOR_DEVICE: "Samsung Galaxy S10" + WEB_VNC: false + options: + --device /dev/kvm + steps: + - name: Wait For AVD To Startup-等待模拟器启动 + uses: jakejarvis/wait-action@v0.1.1 + with: + time: '60s' + - name: Checkout-检出项目 uses: actions/checkout@v4 - name: Env Setup uses: ./.github/actions/env_setup + - name: unittest + run: | + poetry run -m unittest discover -s ./tests/ -p "test_*.py" + poetry run robot tests \ No newline at end of file diff --git a/robotframework_airtest/poco/std.py b/robotframework_airtest/poco/std.py index 92895d9..e3f29bf 100644 --- a/robotframework_airtest/poco/std.py +++ b/robotframework_airtest/poco/std.py @@ -31,7 +31,7 @@ # 查询信息hh class QueryInfo(NamedTuple): - name: str + name: Optional[str] = None attrs: Dict[str, Any] = {} @@ -68,13 +68,13 @@ def parse_url_to_queryinfos(url: Optional[PocoURL], **attrs) -> List[QueryInfo]: # logger.console("parsing:{} {}".format(path, attrs)) query_infos: list[QueryInfo] = [] if url is None: - query_info = QueryInfo("", attrs=attrs) + query_info = QueryInfo(None, attrs=attrs) query_infos.append(query_info) else: urls: list[str] = url.split("\\") for index, url in enumerate(urls): d = urlparse(url) - path = d.path if d.path else "" + path = d.path if d.path else None ext_attrs = dict(parse_qsl(d.query)) query_info = QueryInfo(name=path, attrs=ext_attrs) if index == len(urls) - 1: @@ -164,7 +164,7 @@ def poco(self) -> StdPoco: return self._poco @property - def focusing_element(self) -> UIObjectProxy: + def focusing_element(self): """获取当前聚焦元素 Returns: @@ -174,8 +174,6 @@ def focusing_element(self) -> UIObjectProxy: if self.focusing_elements: # 栈顶元素就是当前聚焦的元素 return self.focusing_elements[-1] - # 不然就返回根元素 - return self.poco() @property def airtest_log_dir(self) -> str: @@ -341,10 +339,16 @@ def _query( node = None # 在当前聚焦元素下查询第一个元素 - node = self.focusing_element.offspring(queryinfo.name, **queryinfo.attrs) + if self.focusing_element: + node = self.focusing_element.offspring( + name=queryinfo.name, # type:ignore + **queryinfo.attrs, + ) + else: + node = self.poco(name=queryinfo.name, **queryinfo.attrs) # type: ignore for queryinfo in queryinfos[1:]: - node = node.offspring(queryinfo.name, **queryinfo.attrs) + node = node.offspring(queryinfo.name, **queryinfo.attrs) # type: ignore # 接着往下查询 return node @@ -458,12 +462,12 @@ def focus_element( element = self._query(target) self.focusing_elements.append(element) - logger.debug( - "聚焦元素 {} {}".format( - self.focusing_element, self.focusing_element.get_name() + if self.focusing_element: + logger.debug( + "聚焦元素 {} {}".format( + self.focusing_element, self.focusing_element.get_name() + ) ) - ) - logger.debug(self.focusing_elements) @deco.keyword("结束聚焦元素") def end_focus_element(self): diff --git a/tests/demo/com.netease.poco.u3d.tutorial_Data/output_log.txt b/tests/demo/com.netease.poco.u3d.tutorial_Data/output_log.txt index 2316678..87cf32b 100644 --- a/tests/demo/com.netease.poco.u3d.tutorial_Data/output_log.txt +++ b/tests/demo/com.netease.poco.u3d.tutorial_Data/output_log.txt @@ -6,29 +6,29 @@ Direct3D: Vendor: NVIDIA VRAM: 24156 MB Begin MonoManager ReloadAssembly -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.dll (this message is harmless) -Loading c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.dll into Unity Child Domain -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Assembly-CSharp.dll (this message is harmless) -Loading c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Assembly-CSharp.dll into Unity Child Domain -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.UI.dll (this message is harmless) -Loading c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.UI.dll into Unity Child Domain -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.Networking.dll (this message is harmless) -Loading c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.Networking.dll into Unity Child Domain -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Newtonsoft.Json.dll (this message is harmless) -Loading c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Newtonsoft.Json.dll into Unity Child Domain -- Completed reload, in 0.024 seconds -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\System.Core.dll (this message is harmless) -Platform assembly: c:\Users\john\Documents\Projects\Github\xtester_robot\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\System.dll (this message is harmless) +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.dll (this message is harmless) +Loading C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.dll into Unity Child Domain +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Assembly-CSharp.dll (this message is harmless) +Loading C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Assembly-CSharp.dll into Unity Child Domain +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.UI.dll (this message is harmless) +Loading C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.UI.dll into Unity Child Domain +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.Networking.dll (this message is harmless) +Loading C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\UnityEngine.Networking.dll into Unity Child Domain +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Newtonsoft.Json.dll (this message is harmless) +Loading C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\Newtonsoft.Json.dll into Unity Child Domain +- Completed reload, in 0.032 seconds +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\System.Core.dll (this message is harmless) +Platform assembly: C:\Users\kalul\Documents\GitHub\robotframework-airtest\tests\demo\com.netease.poco.u3d.tutorial_Data\Managed\System.dll (this message is harmless) Initializing input. Input initialized. desktop: 5120x1440 120Hz; virtual: 5120x1440 at 0,0 Initialized touch support. -UnloadTime: 0.342800 ms +UnloadTime: 0.341600 ms Tcp server started (Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37) -a3fa9accefc1a12e3a7eb344b9a7e040 +1e0d25cd307f5ca045c1c3631f95cceb (Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37) @@ -45,9 +45,9 @@ SocketException: 由于套接字没有连接并且(当使用一个 sendto 调用 (Filename: Line: -1) Setting up 6 worker threads for Enlighten. - Thread -> id: 9894 -> priority: 1 - Thread -> id: 9740 -> priority: 1 - Thread -> id: 6fe4 -> priority: 1 - Thread -> id: 9698 -> priority: 1 - Thread -> id: 836c -> priority: 1 - Thread -> id: 5500 -> priority: 1 + Thread -> id: 2f44 -> priority: 1 + Thread -> id: 5c60 -> priority: 1 + Thread -> id: 60f8 -> priority: 1 + Thread -> id: 7e60 -> priority: 1 + Thread -> id: 2994 -> priority: 1 + Thread -> id: 6e3c -> priority: 1 diff --git a/tests/test_device_library.py b/tests/test_device_library.py index 4d07797..d8b6f6e 100644 --- a/tests/test_device_library.py +++ b/tests/test_device_library.py @@ -91,7 +91,7 @@ class TestAppManage(unittest.TestCase): def setUpClass(cls): cls.dev_lib = DeviceLibrary(device_uri="android:///") cls.dev_lib.connect_device() - cls.dev_lib.install_app(APP_PACKAGE) + cls.dev_lib.install_app(APP_PATH) @classmethod def tearDownClass(cls):