1

I'm trying to test a Mobile Website with Selenium and nodeJS.
Thats way I'm trying to simulate user interaction with a touch and/or swipe, but I could find any solution, that work with my Application.

I found this two SO Post that kind of ask the same:

How do I programmatically create a TouchEvent in Chrome 41? and WebDriver simulate touch events in Desktop Browser

But both generate TouchEvents, that are not trusted (so recognizable as no real human interaction). And this is not useful since the Application tests if the Events (TouchEvent) are trusted. MDN Link to isTrusted

I couldn't find anything about creating/simulating TouchEvents in the online Documentation of selenium-webdriver, and faking touchEvents with driver.executeScript as mentioned above creates untrusted Events. (what is clear because if not, any Website could fake user interaction)

And the application tests (apart of some other things), for

document.body.addEventListener("touchstart", e => {
    evt.preventDefault();
    ...
    if (e.isTrusted) {
      /* The event is trusted do STUFF */
        ...
    } 
});

My main Question is, can selenium create trusted (Touch) Events, with on Chrome(Main Browser we use for testing) with nodeJs(or any other language if it needs to)?
Alternative: Is the a workaround, that doesn't involve changing the application Code? I would even consider using a different modern browser, that plays well with selenium.

winner_joiner
  • 12,173
  • 4
  • 36
  • 61
  • Do you have to use Selenium? The browser automation tool Puppeteer says it sends trusted events: https://pptr.dev/ (search the page for "trusted") https://pptr.dev/#?product=Puppeteer&version=v13.4.0&show=api-class-touchscreen – Doug Naphas Feb 26 '22 at 22:04
  • @DougNaphas Thanks for the information, I solved this by altering the application code. But I will look into it for the next tests. – winner_joiner Mar 03 '22 at 19:44

1 Answers1

1

I have played with selenium a long time ago.

As I recall there are multiple triggers that "flag" you and show it was an automated process instead of a human. You have the patterns of human activity (time taken to press, if the touch/click was exactly at the center of a button or multiple times at the exact location, the patterns of time and moves before achieving something), and then you have some software triggered flags (when using web there are JS scripts checking for the browser metadata, user agent, certifications, and there are even some flags set by selenium on purpose.

From my point of view all the above depends on where you want to use it. But I should recommend you reading more here on Bot Detection

Waelmas
  • 1,894
  • 1
  • 9
  • 19
  • thanks for your response, but I'm trying to test the Application, not secure it from Bot's. I'm looking for a way to simulate "real" touch events in Selenium-webdriver. – winner_joiner Nov 15 '19 at 10:57