Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use normal element #236

Merged
merged 6 commits into from
Aug 19, 2018
Merged

use normal element #236

merged 6 commits into from
Aug 19, 2018

Conversation

KazuCocoa
Copy link
Member

appium/appium-base-driver#235 was merged. Thus, we can remove customised image elements introduced in #224 since we can get coordinates by rect, location and size, I think. right? @jlipps
(Following Java and Ruby client did)


Tests:

You can see some commands like /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/rect after getting a result of -image

[HTTP] --> POST /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element
[HTTP] {"using":"-image","value":"iVBORw0KGgoAAAANSUhEUgAAAdsAAAA3CAYAAABEi+B5AAAMJ2lDQ1BJQ0MgUHJvZmlsZQAASImVlwdYU8kWgOeWJCQktEAEpITeBOlVamgRBKSDjZAEEkqMCUHEjiwquBZULFjRVREF1wLIoiL2sijY68OCirIuFmyovEkC6Or33vvefN/c+98zZ86cc+7MfDMAqMdwxOIcVAOAXFGeJDYsiJmcksokPQQowACUAgaHKxUHxsREQgZD73+Wd9cBIn9fsZfb+rn9vxZNHl/KBQCJgZzOk3JzIR8EAHfniiV5ABB6oNxsep4YMlHuj7YEOgjZXM6ZSvaUc7qSIxU68bEsyGkAqFA5HEkmAGpyv5j53ExoR20JZEcRTyiC3AzZjyvg8CB/hjwqN3cqZHVryNbp39nJ/IfN9GGbHE7mMCtjURSVYKFUnMOZ8X+m43+X3BzZ0BhmsFIFkvBYeczyvGVPjZAzFfJZUXpUNGQtyFeFPIW+nJ8IZOEJg/ofuFIWzBlgAIBSeZzgCMgGkE1FOVGRg3K/DGEoGzLMPRovzGPHK/uiPMnU2EH7aAFfGhI3xByJYiy5TqksOyFw0OYmAZ89ZLOpUBCfpPQ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CNlRgxyZJ4gPV/bFJnM5Ct90IWfxpcmRQ37y+MEhyriwIr4oYdB/rFycFxQ7qL9dnBMzqI8183PC5HJTyG3S/Lihvr15cLIp48WBOC8mXukbrp3FGRuj9AG3BZGABYIBE8hgTQdTQRYQtvU09MAvZUso4AAJyAR8YD8oGeqRpGgRwWccKAR/QeID6XC/IEUrH+RD+ZdhqfJpDzIUrfmKHtngCeRcEAFy4LdM0Us0PFoieAwlwp9G50Jfc2CVt/0kY6oPyYghxGBiODGUaIPr4364Dx4JnwGwOuOeuNeQX9/0CU8I7YSHhGuETsKtKcIiyQ+eM8E40Al9DB2MLv...
[BaseDriver] Finding image element with match threshold 0.4
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"getDeviceSize","params":{}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"getDeviceSize","params":{}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getDeviceSize
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"height":1794,"width":1080}}
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [ADB] Device API level: 25
[BaseDriver] Verifying screenshot size and aspect ratio
[BaseDriver] When trying to find an element, determined that the screen aspect ratio and screenshot aspect ratio are different. Screen is 1080x1794 whereas screenshot is 1080x1920.
[BaseDriver] Resizing screenshot to 1155.8528428093646x1920 to match screen aspect ratio so that image element coordinates have a greater chance of being correct.
[BaseDriver] Scaling screenshot from 1155.8528428093646x1920 to match screen at 1080x1794
[BaseDriver] Image template matched: {"x":8,"y":1,"width":475,"height":55}
[debug] [W3C] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc"}
[HTTP] <-- POST /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element 200 3599 ms - 109
[HTTP]
[HTTP] --> GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/size
[HTTP] {"id":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","sessionId":"bf8df057-4e6d-4920-8be7-26b8a9fe9e68"}
[debug] [W3C] Calling AppiumDriver.getSize() with args: ["appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","bf8df057-4e6d-4920-8be7-26b8a9fe9e68"]
[debug] [W3C] Responding to client with driver.getSize() result: {"width":475,"height":55}
[HTTP] <-- GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/size 200 3 ms - 35
[HTTP]
[HTTP] --> GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/location
[HTTP] {"id":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","sessionId":"bf8df057-4e6d-4920-8be7-26b8a9fe9e68"}
[debug] [W3C] Calling AppiumDriver.getLocation() with args: ["appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","bf8df057-4e6d-4920-8be7-26b8a9fe9e68"]
[debug] [W3C] Responding to client with driver.getLocation() result: {"x":8,"y":1}
[HTTP] <-- GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/location 200 2 ms - 23
[HTTP]
[HTTP] --> GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/rect
[HTTP] {"id":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","sessionId":"bf8df057-4e6d-4920-8be7-26b8a9fe9e68"}
[debug] [W3C] Calling AppiumDriver.getElementRect() with args: ["appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","bf8df057-4e6d-4920-8be7-26b8a9fe9e68"]
[debug] [W3C] Responding to client with driver.getElementRect() result: {"x":8,"y":1,"width":475,"height":55}
[HTTP] <-- GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/rect 200 2 ms - 47
[HTTP]
[HTTP] --> GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/displayed
[HTTP] {"id":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","sessionId":"bf8df057-4e6d-4920-8be7-26b8a9fe9e68"}
[debug] [W3C] Calling AppiumDriver.elementDisplayed() with args: ["appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","bf8df057-4e6d-4920-8be7-26b8a9fe9e68"]
[debug] [W3C] Responding to client with driver.elementDisplayed() result: true
[HTTP] <-- GET /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/displayed 200 2 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/bf8df057-4e6d-4920-8be7-26b8a9fe9e68/element/appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc/click
[HTTP] {"id":"appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","sessionId":"bf8df057-4e6d-4920-8be7-26b8a9fe9e68"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["appium-image-element-4810adbb-4c21-4c2d-a2be-be7dfd80f8dc","bf8df057-4e6d-4920-8be7-26b8a9fe9e68"]

@KazuCocoa KazuCocoa requested a review from jlipps August 5, 2018 08:46
with open(png_img_path, 'rb') as png_file:
b64_data = base64.b64encode(png_file.read()).decode('UTF-8')

return self.find_elements(by=By.IMAGE, value=b64_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java I call this locator type By.imageTemplate. How do you think which one is more appropriate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah =>

By.IMAGE = MobileBy.IMAGE


  1. As a user, if users should imagine what logic is used behind the method, it's better to use template since it help users clalify the behaviour, I think. Then, I'd like to define -image template as the selector though.

  2. We defined the selector as -image. Then, using image in both By and Selector is more appropriate, I felt.

Comparing 1 and 2, so far, 2 is enough, I think. (By.IMAGE is much enough.)

(I considered the naming, too 🤔 )


return self.find_element(by=By.IMAGE, value=b64_data)

def find_elements_by_image(self, png_img_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is no necessarily a png file. The format might be anything support by OpenCV itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡

@KazuCocoa KazuCocoa merged commit feb4b04 into appium:master Aug 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants