Telefonica / toolium

Wrapper tool of Selenium and Appium libraries to test web and mobile applications in a single project
Apache License 2.0
115 stars 62 forks source link

crop_element method in visual_test.py doesn't work properly #288

Closed DuXspace closed 2 years ago

DuXspace commented 2 years ago

Hello! I tried to assert_screenshot for a local chromedriver and it doesn't crop it properly.

As i see the problem is in crop_element method in visual_test.py Also it works the same for appium(android and ios drivers)

page_logo

test file example:

from selenium.webdriver.common.by import By from toolium.pageobjects.page_object import PageObject from toolium.pageelements.page_element import PageElement

class BasicSite(PageObject): base_url = "https://www.basicwebsiteexample.com/" basic_site_logo = PageElement(By.ID, "page-zonestemplate-widgetscompanyname-companyname")

def test_sample(driver_wrapper): driver_wrapper.driver.get(BasicSite.base_url) BasicSite().basic_site_logo.assert_screenshot("page_logo")

In test i used pytest_fixtures from toolium library. In properties.cfg I also tried to add a browser settings like window_width and window_height, but it doesn't help

Maybe you have an idea how to solve that problem?

rgonalo commented 2 years ago

Hi @DuXspace , I have run a test with your example code:

    def test_issue_288(self):
        self.driver.get("https://www.basicwebsiteexample.com/")
        basic_site_logo = PageElement(By.ID, "page-zones__template-widgets__companyname-companyname")
        basic_site_logo.assert_screenshot('companyname')

and the cropped image is the same in a local firefox (v100) than in a local chrome (v101): 01_companyname__test_issue_288 I don't know what is different in your case.

DuXspace commented 2 years ago

@rgonalo Hello, can you check it by cloning this simple project? https://github.com/DuXspace/issue-288 (I'm using toolium 2.6.0) I have no idea why it works in that way, I have already tried local firefox/chrome/Android Chrome/iOS safari on 2 different macos(m1, intel) with different screen resolutions. Also i tried to run it on remote selenoid server, and it works properly, looks like somehow coordinates of web_element is wrong for local running.

rgonalo commented 2 years ago

We have already found the source of the problem. It happens in Mac retina displays or other devices (Android/iOS) which pixel ratio is not 1. We will try to take the device pixel ratio in account when cropping elements in visualtesting, but in the meanwhile you could force in your tests the ratio to 1:

Chrome

[ChromeArguments]
force-device-scale-factor: 1

Firefox

[FirefoxPreferences]
layout.css.devPixelsPerPx: 1.0
DuXspace commented 2 years ago

@rgonalo Thank you very much for your help and help in solving the problem! But it won't to help for safari driver on iOS (https://appium.io/docs/en/drivers/safari/)

I thought a lot about just copying the visual testing file to our project, but due to the philosophy of the framework, which I really like, I would like this framework to be improved too. Also there is a safari driver that does not support some selenium methods (commands), I would like to know one thing. Will you fix such things if I start creating tasks for these problems or if it is needed to be done by us. I can create a list of problems and their solutions that we found and made on our side, I think this would be helpful for the universatility of the framework.

Also maybe you have a telegram chat or something like this, I think it will help to populize a framework!

rgonalo commented 2 years ago

I would really appreciate that you become a toolium contributor. You can create the issues and fix them yourself or wait for us to solve them, but it would be faster if you push the solution.

VladimirPodolian commented 2 years ago

@rgonalo @DuXspace Hi! Please take a look for my fix when you have time and also i have fixed same problem in Android and iOS platform. Please give me feedback is it resolve the issue or not.

DuXspace commented 2 years ago

@rgonalo Looks like all works properly, can you check it too and merge it?

rgonalo commented 2 years ago

I've just reviewed and merged it. Thanks for contributing @DuXspace @VladimirPodolyan

VladimirPodolian commented 2 years ago

@rgonalo is it possible to roll out current dev version to pypi?

rgonalo commented 2 years ago

This issue is fixed in 2.6.1 version, that is already released and published in pypi