healenium / healenium-web

Self-healing library for Selenium Web-based tests
Apache License 2.0
169 stars 40 forks source link

When findElements returns more then one WebElement Healenium tries to heal it for some reason #130

Closed OlegsTolstovs closed 2 years ago

OlegsTolstovs commented 3 years ago

In our application I have list of Employees displayed and for each Employee Name WebElement FrontEnd developer added "data-testid" attribute to help with test automation.

I need to get list of WebElements to get Names of Employees using this xpath: By.xpath("//span[@data-testid='EmployeeName']")

It works fine without "healing" but with healing on Healenium tries to heal each WebElement from list and writes this in log: 15:43:52 Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div > div > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(2) > span)] Aug 13, 2021 3:43:52 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver WARNING: Augmenter should be applied to the instances of @Augmentable classes or previously augmented instances only (instance class was: class org.openqa.selenium.chrome.ChromeDriver) 15:43:57 Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div > div > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(3) > span)] Aug 13, 2021 3:43:57 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver WARNING: Augmenter should be applied to the instances of @Augmentable classes or previously augmented instances only (instance class was: class org.openqa.selenium.chrome.ChromeDriver) 15:44:03 Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div > div > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(4) > span)] Aug 13, 2021 3:44:03 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver WARNING: Augmenter should be applied to the instances of @Augmentable classes or previously augmented instances only (instance class was: class org.openqa.selenium.chrome.ChromeDriver)

Any good reason why it tries to heal it?

Version I am using: healenium-web 3.1.4 healenium/hlm-backend 3.1.2 healenium/hlm-selector-imitator 1

KritikaSahare1611 commented 3 years ago

agree with @OlegsTolstovs, with healing on, Healenium tries to heal each WebElement from list and writes this in log.

[TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9142857142857143, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(1) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9639097744360902, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(1) > div > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(2) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(3) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(4) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(5) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(6) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(7) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(8) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(9) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=1.0, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(10) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9142857142857143, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(1) > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9639097744360902, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(2) > div > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9639097744360902, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(3) > div > div)] [TestNG-tests-3] WARN com.epam.healenium.service.impl.HealingServiceImpl - Using healed locator: Optional[Scored(score=0.9639097744360902, value=By.cssSelector: html > body > div:nth-child(2) > div > div > div:nth-child(1) > div > div > div:nth-child(1) > div > div > div:nth-child(2) > a:nth-child(4) > div > div)]

@Aliaksei-Ashukha could you please tell, why it is happening? .

Rajesh-Narayanappa87 commented 3 years ago

Interested to contribute. Can I start with this?

Alex-Reif commented 3 years ago

Hi @Rajesh-Narayanappa87 , @KritikaSahare1611 , @OlegsTolstovs

Issue was fixed at v. 3.1.5

OlegsTolstovs commented 3 years ago

Hi!

After this update seems that element search from parent WebElement is not working properly.

We quite often use element search from parent element using this function: public static WebElement getElement(WebElement parent, By locator) { return parent.findElement(locator); }

Now seems we find elements by only using "By locator" as if we do not have parent WebElement.

Same for "parent.findElement(locator)" and "parent.findElements(locator)"

ElenaStepuro commented 3 years ago

Hello @OlegsTolstovs,

Could you please describe what test logic do you expect via running autotest with parent.findElement(locator) and what actually do you see? I mean step`s sequence with elements that should be healed.

OlegsTolstovs commented 3 years ago

Hi!

I am trying out 'Healenium' on ongoing project and where we are using child-parent elements quite a lot, as example we have parent element that indicates some form, popup or dialog and there are defined elements that rely on parent element.

For example we are working with dialog, then dialog itself is parent WebElement and buttons on this dialog are child elements. When we want to press some button on this dialog framework will first find parent WebElement using usual 'parent=driver.findElement(parentLocator)' and then we will try to find specific button using this function: parent.findElement(childLocator).

Now when we call parent.findElement(childLocator) it behaves same way as we would call 'driver.findElement(childLocator)' and since "childLocator" is not unique we are finding wrong elements.

Agree that in healing context its hard to understand what needs to be healed but I do not think that initial WebDriver behavior should be changed.

Alex-Reif commented 2 years ago

Hi @OlegsTolstovs , Issue was fixed at 3.1.6v