honeynet / droidbot

A lightweight test input generator for Android. Similar to Monkey, but with more intelligence and cool features!
MIT License
812 stars 234 forks source link

Other selectors for the view #101

Open archer29m opened 5 years ago

archer29m commented 5 years ago

Hello,

Is there a way that I can add more selectors (other than 'text', 'resource_id', 'class', 'out_coordinates', and 'in_coordinates') for a view? For example a 'content-desc'?

And is there any example for 'in_coordinates' usage? E.g., if there is a button with [35,1500] and [120,1600] coordinates, what should I put for 'in_coordinates' or 'out_coordinates' values in the script json file? I see they are defined as follows:

'out_coordinates': [(INTEGER_VAL, INTEGER_VAL)] 'in_coordinates': [(INTEGER_VAL, INTEGER_VAL)]

So should the view be defined as something like the following: "view_1": { "in_coordinates": "[(100,1550)]", "class": ".*Button" } But, it doesn't match the view. So is there any example for 'in_coordinates' or 'out_coordinates' usage? Thanks

archer29m commented 5 years ago

I found what is wrong. Following two lines in input_script.py file are wrong:

line 282: for out_coordinate in grammar_value: it should be for out_coordinate in selector_value: and line 286: for in_coordinate in grammar_value: it should be for in_coordinate in selector_value:

because grammar_value is always (0,0) and doesn't contain the actual values as it is only for grammar check purposes. I fixed it by using the dict value of selector_value (I used literal_eval for this purpose) and now it works.

junior291492659 commented 5 years ago

I found what is wrong. Following two lines in input_script.py file are wrong:

line 282: for out_coordinate in grammar_value: it should be for out_coordinate in selector_value: and line 286: for in_coordinate in grammar_value: it should be for in_coordinate in selector_value:

because grammar_value is always (0,0) and doesn't contain the actual values as it is only for grammar check purposes. I fixed it by using the dict value of selector_value (I used literal_eval for this purpose) and now it works.

Hello, I have also encountered with this problem and used "selector_value" instead of "grammer_value" in input_script.py, but then I wonder what the correct format of view defined in script should be since I have read the method check_grammar_is_coordinate(value) and tried the following:

  1. "view_1": { "in_coordinates": "[(100,1550)]", "class": ".*Button" }

  2. "view_1": { "in_coordinates": ["(100,1550)"], "class": ".*Button" }

and neither of them works, both of them can not pass the method check_grammar_is_coordinate(value)

It would be really appreciated to get your reply.

archer29m commented 5 years ago

There is something wrong for that check point too. I removed it for coordinates, and it works. So just remove the following check point:

DroidBotScript.check_grammar_is_coordinate(in_coordinate)

and make sure to use the correct format as follows:

"in_coordinates": "[(100, 1550)]"

yuanchun-li commented 5 years ago

Hi guys,

I have to say everything related to script is not well tested. Thank you for pointing out so many issues.

Regarding your questions:

Is there a way that I can add more selectors (other than 'text', 'resource_id', 'class', 'out_coordinates', and 'in_coordinates') for a view? For example a 'content-desc'?

You have to modify the source yourself. You many want to set breakpoint at adapter/droidbot_app.py to see what fields other thantext,resource_id`, etc. are in a view.

Is there any example for 'in_coordinates' usage?

Sorry, there isn't. in_coordinates are supposed to be some coordinates inside the view that you want to select, while out_coordinates are supposed to be outside of the view. However, I hadn't used them. It seems @archer29m 's fix is correct.

The correct syntax for 'in_coordinates' and 'out_coordinates'

The correct definition should be: 'out_coordinates': [[INTEGER_VAL, INTEGER_VAL]] 'in_coordinates': [[INTEGER_VAL, INTEGER_VAL]] Each coordinate should be a 2-element list instead of a tuple.

I just created a PR with the possible fix, however I haven't tested it yet.