Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Piotr Rudnicki
@piotrrudnicki_gitlab
Hello! Quick (I hope) question. Where in python code can I disable app closing on exception? I would rather keep it open to see my logs from Unity, than close and lose it.
jeremygram
@jeremygram

this fails:

    def test_find_objects_fail(self):
        self.altdriver.load_scene('Scene 1 AltUnityDriverTestScene')
        plane = self.altdriver.wait_for_object(By.NAME, 'Plane')
        capsule = self.altdriver.wait_for_object(By.NAME, 'Capsule')
        self.assertEqual('Plane', plane.name)
        self.assertEqual('Capsule', capsule.name)

and this fails:

    def test_find_objects_fail(self):
        self.altdriver.load_scene('Scene 1 AltUnityDriverTestScene')
        plane = self.altdriver.wait_for_object(By.NAME, 'Plane')
        time.sleep(3)
        capsule = self.altdriver.wait_for_object(By.NAME, 'Capsule')
        self.assertEqual('Plane', plane.name)
        self.assertEqual('Capsule', capsule.name)

but this passes:

    def test_find_objects_fail(self):
        self.altdriver.load_scene('Scene 1 AltUnityDriverTestScene')
        plane = self.altdriver.wait_for_object(By.NAME, 'Plane')
        self.altdriver.move_mouse(0, 0, 1)
        capsule = self.altdriver.wait_for_object(By.NAME, 'Capsule')
        self.assertEqual('Plane', plane.name)
        self.assertEqual('Capsule', capsule.name)

i can see in the logs when it fails:

Waiting for element Plane...
Received data was: {"name":"Plane",
Element Plane found at x:1012 y:595 mobileY:485
Received data was: {"name":"Plane",
Element Plane found at x:1012 y:595 mobileY:485

Robert Poienar
@robert_poienar_gitlab
@piotrrudnicki_gitlab are you using with appium?
Piotr Rudnicki
@piotrrudnicki_gitlab
yup
jeremygram
@jeremygram
it's like it gets stuck on that command. but if i put some other unrelated command it there then it seems to get flushed properly
Robert Poienar
@robert_poienar_gitlab
@piotrrudnicki_gitlab remove from tearDownClass: cls.driver.quit()
Piotr Rudnicki
@piotrrudnicki_gitlab
Where's that class? I can't find it :(
Robert Poienar
@robert_poienar_gitlab
In our example file: python_appium_tests.py is at line 31
Piotr Rudnicki
@piotrrudnicki_gitlab
Ah, in test ;) Of course. Thanks!
jeremygram
@jeremygram

@robert_poienar_gitlab are you on mac? can you find your appium-python-client version?

pip show Appium-Python-Client

Robert Poienar
@robert_poienar_gitlab
I'm on Windows, my Appium-Python-Client is 0.40.
but I don't think is an appium problem for that test
Robert Poienar
@robert_poienar_gitlab
@jeremygram can you please send me the logs you get after running the test?
jeremygram
@jeremygram
@robert_poienar_gitlab what's a good way to share files with you? or maybe i should just private chat so i don't spam the channel?
Robert Poienar
@robert_poienar_gitlab
yeah, just send it in private
jeremygram
@jeremygram
ah! @robert_poienar_gitlab the commands are multiplying for each test. i can guess the problem now.
AltUnityRunnerPrefab is saved in the scene, but the test is loading the scene over and over
so i'm getting a bunch of AltUnityRunnerPrefab
i bet the unity tests don't call LoadScene for each test, so this doesn't happen when running in the editor
Robert Poienar
@robert_poienar_gitlab
The AltUnityRunnerPrefab is a singleton so if there are more than one it will be destroyed.
jeremygram
@jeremygram
ya you're right. that didn't fix anything :(
jeremygram
@jeremygram
i think i see the issue:
  • in python i call self.altdriver.wait_for_object(By.NAME, 'Plane')
  • wait_for_object calls FindObject which calls send_data and sends the command to the Unity client
  • send_data throws an exception for some reason (still investigating this -- there are like 30 implementations of socket.send and i don't know which one is being used), so FindObject fails, sleeps, and tries again.
  • the Unity client receives that first send_data command anyways, processes it, and sends the response back to python
  • wait_for_object in python sends the request AGAIN because the first request failed (this logic is built into the function)
  • (this part i am guessing:) the second call to wait_for_object ends up getting the response to the FIRST call that failed on the python side but succeeded on the Unity client. the responses to all further calls to the Unity client are now off by 1.
Ru Cindrea
@ru.cindrea_gitlab
@jeremygram do you have the same problem with any two element searches in a row? have you tried searching for something else?
Robert Poienar
@robert_poienar_gitlab
@jeremygram I don't know what I did, but now I can reproduce your problem. I let you know if I found a solution.
jeremygram
@jeremygram
awesome, thanks robert
jeremygram
@jeremygram
ok! i think i found the issue. it's not FindObject that throws everything off by 1, it's actually the scene load
=== send data: getCurrentScene;&
01/22/2020 10:17:01: response received: {"name":"Scene 0 Bootstrap",...
Element Scene 0 Bootstrap found at x:0 y:0 mobileY:0
Current scene is Scene 0 Bootstrap
=== send data: enableLogging;false;&
01/22/2020 10:17:01: response received: Ok
Received data was: Ok
=== send data: loadScene;Scene 1 AltUnityDriverTestScene;&
01/22/2020 10:17:01: response received: Ok
Received data was: Ok
Scene loaded: Scene 1 AltUnityDriverTestScene
=== send data: findActiveObjectByName;Plane;;true;&
01/22/2020 10:17:01: response received: Scene Loaded
Received data was: Scene Loaded
FindObject failed for element Plane: Expecting value: line 1 column 1 (char 0)
Wait 0.5 seconds then try again ...
FindObject fails with an exception because it's actually receiving "Scene Loaded" as the response
    def test_find_element(self):
        self.altdriver.load_scene('Scene 1 AltUnityDriverTestScene')
        plane = self.altdriver.wait_for_object(By.NAME, 'Plane')
        capsule = self.altdriver.find_object(By.NAME, 'Capsule')
        eventsystem = self.altdriver.find_object(By.NAME, 'EventSystem')
        light = self.altdriver.find_object(By.NAME, 'Directional Light')
        cube = self.altdriver.find_object(By.NAME, 'Cube', '', False)
        print('plane: {}'.format(plane.name))
        print('capsule: {}'.format(capsule.name))
        print('eventsystem: {}'.format(eventsystem.name))
        print('light: {}'.format(light.name))
        print('cube: {}'.format(cube.name))
=== send data: loadScene;Scene 1 AltUnityDriverTestScene;&
01/22/2020 10:17:01: response received: Ok
=== send data: findActiveObjectByName;Plane;;true;&
01/22/2020 10:17:01: response received: Scene Loaded
FindObject failed for element Plane: Expecting value: line 1 column 1 (char 0)
Wait 0.5 seconds then try again ...
=== send data: findActiveObjectByName;Plane;;true;&
01/22/2020 10:17:02: response received: {"name":"Plane","id":1992,...
Element Plane found at x:1012 y:595 mobileY:485
=== send data: findActiveObjectByName;Capsule;;true;&
01/22/2020 10:17:02: response received: {"name":"Plane","id":1992,...
Element Plane found at x:1012 y:595 mobileY:485
=== send data: findActiveObjectByName;EventSystem;;true;&
01/22/2020 10:17:02: response received: {"name":"Capsule","id":2016,...
Element Capsule found at x:1080 y:688 mobileY:392
=== send data: findActiveObjectByName;Directional Light;;true;&
01/22/2020 10:17:02: response received: {"name":"EventSystem","id":1990,...
Element EventSystem found at x:1073 y:648 mobileY:432
=== send data: findObject;//Cube;;false;&
01/22/2020 10:17:02: response received: {"name":"Directional Light","id":1984,...
Element Directional Light found at x:1097 y:785 mobileY:295
plane: Plane
capsule: Plane
eventsystem: Capsule
light: EventSystem
cube: Directional Light
jeremygram
@jeremygram

load_scene.py

    def execute(self):
        data = self.send_data(self.create_command('loadScene', self.scene_name))
        if (data == 'Ok'):
            print('Scene loaded: ' + self.scene_name)
            return data
        return None

LoadSceneCommand.cs

        public override string Execute()
        {
            AltUnityRunner._altUnityRunner.LogMessage("LoadScene " + scene);
            string response = AltUnityRunner._altUnityRunner.errorNotFoundMessage;
            var sceneLoadingOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene);
            sceneLoadingOperation.completed += SceneLoaded;

            UnityEngine.SceneManagement.SceneManager.LoadScene(scene);
            response = "Ok";
            return response;
        }

        private void SceneLoaded(UnityEngine.AsyncOperation obj)
        {
            AltUnityRunner.logMessage = "Scene Loaded";
            handler.SendResponse("Scene Loaded");
        }
so the python script interprets the 'OK' response to 'loadScene' as the scene being loaded. but in Unity the 'OK' response just means that it received the command, and then it sends 'Scene Loaded' once the scene is actually finished loading.
maybe there's a version mismatch here, between altunityrunner and altunitytester?
jeremygram
@jeremygram
this fixes it:
load_scene.py
    def execute(self):
        data = self.send_data(self.create_command('loadScene', self.scene_name))
        if (data == 'Ok'):
            print('Waiting for scene to load: ' + self.scene_name)
            data = self.recvall()
            if (data == 'Scene Loaded'):
                print('Scene loaded: ' + self.scene_name)
                return data
        return None
but i'm not familiar enough with python to understand if that is robust vs long scene loads on the Unity client. going to test that now.
Robert Poienar
@robert_poienar_gitlab
@jeremygram yeah I think you might be 100% right with the cause of the problem. I know I modified something about the load scene that can cause this issue.
I need to check when I made those modifications.
Robert Poienar
@robert_poienar_gitlab
@jeremygram did you get the server part from gitlab or assetstore?
jeremygram
@jeremygram
cool, it works. i added a 10 second delay to the 'Scene Loaded' response, works as espected
gitlab
Robert Poienar
@robert_poienar_gitlab
and installed the python bindings from pip?
jeremygram
@jeremygram
yes
$ pip install Appium-Python-Client
$ git clone https://github.com/appium/appium.git
$ cd appium/sample-code/python
$ pip install -r requirements.txt
$ pip install deprecated
$ pip install altunityrunner
Robert Poienar
@robert_poienar_gitlab
ok, yeah that is the issue, I added that "Scene is loaded" after the latest release from assetStore and pip, so you have a newer version of server than what the binding is expecting
that is why for us the python test were working, and it didn't worked for you
jeremygram
@jeremygram
ah ok. this is the problem with living on the bleeding edge :D
Robert Poienar
@robert_poienar_gitlab
https://altom.gitlab.io/altunity/altunitytester/pages/download-import.html#bindings check python installation from source code to use the latest modification of python bindings
jeremygram
@jeremygram
thanks
Robert Poienar
@robert_poienar_gitlab
at least we know that we have to prioritize altom/altunity/altunitytester#256 so this kind of problem to not happen in the future.