AirtestProject / Poco

A cross-engine test automation framework based on UI inspection
http://airtest.netease.com/
Apache License 2.0
1.74k stars 315 forks source link

Add functions for Unity method invocations #607

Closed Danand closed 8 months ago

Danand commented 9 months ago

Changes

Example

Here is example usage of UnityPoco.invoke()

Poco-side

poco = UnityPoco()
poco.invoke(listener="say_hello", name="anonymous", year=2024)

Unity-side

  1. Derive some new class from PocoListenerBase

  2. Add method:

    [PocoMethod("say_hello")]
    public void SayHello(string name, int year)
    {
       Debug.Log("Hi, ${name}! {year} is coming soon!");
    }
  3. Add reference at PocoManager to ancestor of PocoListenerBase

Dependencies

This is dependency for https://github.com/AirtestProject/Poco-SDK/pull/123

yimelia commented 8 months ago

hi @Danand

Thank you very much for your PR! I have added a documentation description for this change. https://github.com/AirtestProject/Poco/pull/608/commits/22bf600bcf5c23f0fdedb964e26c33b3716d4680

Please help me check whether this content is correct. If there is no problem, these changes will be updated in the next version.

Danand commented 8 months ago

Please help me check whether this content is correct.

@yimelia Hi! Everything is correct, but it's also worth to mention how to utilize UnityPoco.sendMessage() on Unity-side:

PocoManager.MessageReceived += OnPocoMessageReceived;
Danand commented 8 months ago

@yimelia Also do not forget about PR at Poco-SDK respectively! 😉 https://github.com/AirtestProject/Poco-SDK/pull/123

yimelia commented 8 months ago

hi @Danand

I have updated the document description, but my English is not good and I am not sure whether I have expressed the intended meaning correctly. Please help me confirm the content again. Thank you very much!

https://github.com/AirtestProject/Poco/commit/f229be9738292fa96b37d073e26aa92f107401d2

Danand commented 8 months ago

@yimelia Everything is clear!

yimelia commented 6 months ago

HI @Danand Some of our users have encountered errors after updating the code, can you please help to see how to modify the code to be compatible with this issue? image

Danand commented 6 months ago

how to modify the code to be compatible with this issue?

@yimelia Hi!

I guess, simple null check goes here:

if (listeners == null)
{
    return;
}

at before PocoListenerUtils.cs:14

Sorry for the inconvenience. I didn't test properly so far. This functionality must be optional (no assigned PocoListenersBase), but I missed that somehow.

yimelia commented 6 months ago

When users update their SDK code, this error seems to be triggered if they do nothing.. @Danand

Danand commented 6 months ago

@yimelia It's because no object assigned to PocoManager.pocoListenersBase by default, it's my bad.

Users could fix error for now, that way: add component PocoListenersBase and assign it to field pocoListenersBase of PocoManager component. Error should be gone.

yimelia commented 6 months ago

Can the code be changed so that users can run it smoothly without any operations, if they don't need this new feature?

Danand commented 6 months ago

@yimelia Yes, I suggested fix here: https://github.com/AirtestProject/Poco/pull/607#issuecomment-1983095687