Ошибка при попытке провести к org.openqa.selenium.remote.RemoteWebDriver не может быть приведена к org.openqa.selenium.interactions.HasTouchScreen - PullRequest
0 голосов
/ 06 февраля 2020

Я пытаюсь провести в приложении, и оно вызывает следующую ошибку: 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("bobby.chodagam@yellowfin.bi");
		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

1 Ответ

0 голосов
/ 07 февраля 2020

Я решил проблему, объявив следующим образом:

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 Yf {

	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("bobby.chodagam@yellowfin.bi");
		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);
		
	}
}
...