尝试滑动到org.openqa.selenium.remote.RemoteWebDriver时出错,无法转换为org.openqa.selenium.interactions.HasTouchScreen

问题描述 投票:0回答:1

[我正在尝试在应用程序中滑动,它给我以下错误org.openqa.selenium.remote.RemoteWebDriver无法转换为org.openqa.selenium.interactions.HasTouchScreen]

请找到我的代码详细信息。这是我的主班

public class Yf {

	WebDriver driver;
	// String path = System.getProperty("user.dir");

	WebDriverWait wait;

	DesiredCapabilities cap = new DesiredCapabilities();
	Swipe swipe = new Swipe(driver);

	@BeforeTest
	public void initConfig() {

		cap.setCapability("deviceName", "R58M439LBRY");
		cap.setCapability("platformName", "Android");
		// cap.setCapability(CapabilityType.BROWSER_NAME, "Android");
		cap.setCapability(CapabilityType.VERSION, "9");
		cap.setCapability("appPackage", "com.yellowfinbi.android");
		cap.setCapability("appActivity", "md5a479f257bdebd299ec30f02ebca2a5d0.LaunchActivity");

	}

	@Test
	public void Login() throws MalformedURLException, InterruptedException {
		RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
		WebElement SignInButton = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Login')]"));
		SignInButton.click();
		Thread.sleep(2000);
		WebElement ServerURL = driver
				.findElement(By.xpath("//android.widget.EditText[contains(@text,'Server URL (or address)')]"));
		ServerURL.sendKeys("https://chololo.yellowfin.bi/");
		Thread.sleep(2000);
		WebElement UserName = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Username')]"));
		UserName.sendKeys("[email protected]");
		Thread.sleep(2000);
		WebElement PassWord = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Password')]"));
		PassWord.sendKeys("Sai79baba");
		Thread.sleep(2000);
		WebElement Login = driver.findElement(By.xpath("//android.widget.TextView[contains(@index,'8')]"));
		Login.click();
		Thread.sleep(15000);
		swipe.Scroll(driver, DIRECTION.LEFT, 1000);

	}

}

请在下面找到滑动方法代码

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.Augmenter;

public class Swipe {

	WebDriver driver;

	public Swipe(WebDriver driver) {
		this.driver = driver;
	}

	public enum DIRECTION {
		DOWN, UP, LEFT, RIGHT;
	}

	public void Scroll(WebDriver driver, DIRECTION direction, long duration) {
		Dimension size = driver.manage().window().getSize();
		TouchActions Action = new TouchActions(driver);

		int startX = 0;
		int endX = 0;
		int startY = 0;
		int endY = 0;

		switch (direction) {
		case RIGHT:
			startY = (int) (size.height / 2);
			startX = (int) (size.width * 0.90);
			endX = (int) (size.width * 0.05);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case LEFT:
			startY = (int) (size.height / 2);
			startX = (int) (size.width * 0.05);
			endX = (int) (size.width * 0.90);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case UP:
			endY = (int) (size.height * 0.70);
			startY = (int) (size.height * 0.30);
			startX = (size.width / 2);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case DOWN:
			startY = (int) (size.height * 0.70);
			endY = (int) (size.height * 0.30);
			startX = (size.width / 2);
			Action.scroll(startX, startY).move(startX, endY).release().perform();
			break;

		}
	}

}

[请让我知道我做错了。这也是我尝试向左滑动的应用程序的屏幕截图。谢谢enter image description here

appium appium-android
1个回答
0
投票

我已经通过声明如下解决了该问题

AppiumDriver<MobileElement> driver; and initialising as 
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);

这里是最终代码

mport org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.yellowfin.mobile.Swipe;
import com.yellowfin.mobile.Swipe.DIRECTION;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class Yellowfin {

	AppiumDriver<MobileElement> driver;
	// String path = System.getProperty("user.dir");

	WebDriverWait wait;
	Swipe swipe;
	DesiredCapabilities cap = new DesiredCapabilities();

	@BeforeTest
	public void initConfig() throws MalformedURLException {

		cap.setCapability("deviceName", "R58M439LBRY");
		cap.setCapability("platformName", "Android");
		// cap.setCapability(CapabilityType.BROWSER_NAME, "Android");
		cap.setCapability(CapabilityType.VERSION, "9");
		cap.setCapability("appPackage", "com.yellowfinbi.android");
		cap.setCapability("appActivity", "md5a479f257bdebd299ec30f02ebca2a5d0.LaunchActivity");
		driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
		swipe = new Swipe(driver);
	}

	@Test
	public void Login() throws InterruptedException {

		WebElement SignInButton = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Login')]"));
		SignInButton.click();
		Thread.sleep(2000);
		WebElement ServerURL = driver
				.findElement(By.xpath("//android.widget.EditText[contains(@text,'Server URL (or address)')]"));
		ServerURL.sendKeys("https://chololo.yellowfin.bi/");
		Thread.sleep(2000);
		WebElement UserName = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Username')]"));
		UserName.sendKeys("[email protected]");
		Thread.sleep(2000);
		WebElement PassWord = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Password')]"));
		PassWord.sendKeys("Sai79baba");
		Thread.sleep(2000);
		WebElement Login = driver.findElement(By.xpath("//android.widget.TextView[contains(@index,'8')]"));
		Login.click();
		Thread.sleep(15000);
		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
		
	}
}
© www.soinside.com 2019 - 2024. All rights reserved.