TestProject Forum
Powered by leading experts in the test automation community

Getting access to Selenium WebDriver instance

I am trying to directly use some TouchActions via Selenium, and I’d like to know if it would be possible to access a WebDriver instance from the WebDriverHelper in the execute() method. I currently using the Java SDK.
Please let me know if this question does not make any sense!

Hi @jason.valenzuela,

You can definitely use the driver from the helper instance and use the TouchActions with it.

Let me know if you will need my help with that.

Kind regards,
Amit

Hello @amit.yahav!

Thanks for your help with this! I tried using the driver from the helper instance, but I am currently getting this error:
io.testproject.java.sdk.v2.drivers.WebDriver incompatible with org.openqa.selenium.interactions.HasTouchScreen

This is how I am using the TouchActions API in my test:

val action = TouchActions(driver)
val coordinates = driver?.findElement(pButton)
val x = coordinates?.location?.x!!
val y = coordinates.location?.y!!
action.down(x, y)
action.move(x + 300, y)
action.perform()

What action are you trying to perform?

I am trying to do a drag gesture for mobile devices.

Actually, we already have this action in our “Mobile Etensions”: https://addons.testproject.io/mobile-extensions

I saw that add-on before and tried using it in my project, but it was not working… I’ll give this another shot and report back with any issues.

You can use this action in recorded test and then export it to coded test. That way, you will know how to work with that addon in coded test.

Would it be possible for me to do a recorded session with a mobile browser? I haven’t figured out how to do that.

Hello Jason,

Seems like you are using:

org.openqa.selenium.interactions.touch.TouchActions
Those are incompatible with Appium and deprecated (were implemented in Chrome only).

Try to switching to io.appium.java_client.TouchAction and io.appium.java_client.MultiTouchAction

Also you can use the new Sequence API:

 PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH,"finger1");
 Sequence sequence = new Sequence(finger, 1);
 tap.addAction(finger.create...);
 tap.addAction(finger.create...);
 tap.addAction(finger.create...);
 ...
 helper.getDriver().perform(Arrays.asList(sequence));
1 Like

Hi @jason.valenzuela,

Recording on the mobile browser as the app under test, is the same as recording hybrid application. TestProject is not officially supports hybrid applications. Some of those apps will work just fine in the recorder, but with others, you might have problem to locate the elements.

In coded tests on the other hand, you can definitely test hybrid applications.

1 Like

@marat I tried the PointerInput and Sequence method, and I think I am close! However, when I run the test locally, I get the following error message on my machine:

21 Oct 2019;12:09:22.186 [main] ERROR e.testproject.AcadienceAndroidTest - actions
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'Jasons-MacBook-Pro.local', ip: 'XXX', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '13'
Driver info: driver.version: RemoteWebDriver 
21 Oct 2019;12:09:22.190 [main] INFO  io.testproject.java.sdk.v2.Runner - Execution result: Failed 

It seems that it’s trying to perform the actions on my machine, rather than applying them to the driver on the mobile device I am testing on.

You should add some logging to your code to understand where it fails.
I can help you doing this if you like, feel free to contact us via intercom so that we can schedule a short session.

Following our online support session, since you are creating a pure Web test on Mobile Chrome, as we said you shouldn’t use the org.openqa.selenium.interactions.touch.TouchActions but instead use org.openqa.selenium.interactions.Actions.

Specifically here’s a working example of a web test that performs Drag&Drop:

package io.testproject.examples.sdk.tests;

import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.util.List;

public class DragAndDrop implements WebTest {

    @Override
    public ExecutionResult execute(WebTestHelper helper) throws FailureException {
        WebDriver driver = helper.getDriver();

        driver.navigate().to("https://marcojakob.github.io/dart-dnd/basic/");
        List<WebElement> documents = driver.findElements(By.className("document"));
        WebElement trash = driver.findElement(By.className("trash"));

        Actions act = new Actions(driver);
        for (WebElement document : documents) {
            act.dragAndDrop(document, trash);
        }

        act.build().perform();
        System.out.println("Done!");

        return ExecutionResult.PASSED;
    }
}

This solution worked for me. Thanks @marat!