Scroll event not triggering correctly?

Ouverte
#657 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
html, java, javascript
Domaine
testing

Piste de recherche

Start by reproducing the supplied JUnit test with both ChromeDriver and HtmlUnitDriver; the issue does not name repository files or existing tests to use. Investigate how HtmlUnit handles scrollIntoView and IntersectionObserver, then add a regression test for the behavior. Done means the observer callback increments the count as expected in HtmlUnit, while the Chrome comparison still passes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

I've ran into a case where triggering javascript scrollintoView has no effect, not triggering an event that is supposed to dynamically load the next page of data.

Here is a basic test case:

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;

public class ScrollTest {

    public static final String PAGE;

    static {
        try {
            PAGE = Files.readString(Path.of(ScrollTest.class.getClassLoader().getResource("testPage1.html").toURI()));
        } catch (IOException | URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }

    private static final HtmlUnitDriver huDriver = new HtmlUnitDriver(true);
    private static final WebDriver chromeDriver = new ChromeDriver();

    @AfterAll
    static void closeAll(){
        huDriver.close();
        chromeDriver.close();
    }

    @Test
    void givenPageWithTable_whenScrollTo_TriggerEvent(){
        runTest(chromeDriver);
        runTest(huDriver);
    }

    private static void runTest(WebDriver driver) {
        driver.get(PAGE);
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView()", driver.findElement(By.id("last")));
        Assertions.assertEquals(1L,
                ((JavascriptExecutor) driver).executeScript("return count"));
    }

}

and here is the html file I used for testing, feel free to add more table rows if needed

data:text/html,
<table>
    <tr>row</tr>
    <br>
    <tr id="last"></tr>
</table>
<script>
    var count = 0;
    const observer = new IntersectionObserver((entries) => { 
    entries.forEach((entry) => {
        console.log("triggered");
        count++;
    })
}); 

observer.observe(document.getElementById("last"));
</script>

The results are incosistent:

org.opentest4j.AssertionFailedError: 
Expected :1
Actual   :0
<Click to see difference>

at ScrollTest.runTest(ScrollTest.java:45)
at ScrollTest.givenPageWithTable_whenScrollTo_TriggerEvent(ScrollTest.java:39)

...removed rest of generic stack trace...	
Langage dominant
JavaScript
Étoiles
952
Forks
183
Merge moyen
2 j 1 h
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de HtmlUnit/htmlunit

Toutes les issues de HtmlUnit/htmlunit

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.