【发布时间】:2016-06-24 15:53:20
【问题描述】:
我正在尝试自动化 Salesforce 本机应用程序创建联系页面。我可以在 android mobile 的第一页上看到的所有字段中单击并输入文本。但是对于我在向下滚动页面后得到的其他字段,appium 能够从 appium 日志中找到该字段,但是在单击和发送文本时,它总是发送到第一页上最后编辑的文本框。
如果在使用 appium 滚动页面后需要额外发送文本,请告诉我。
我正在使用 Android 三星 Galaxy S3 设备。下面是代码和 UIAutomator 屏幕截图。
package samsungGalaxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
public class FirstTest {
AndroidDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ce1d12134");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.salesforce.chatter");
capabilities.setCapability("appActivity", "com.salesforce.chatter.Chatter");
capabilities.setCapability("appium-version", "1.4.16.1");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void login() {
driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'home')]")).click();
driver.findElement(By.xpath("//android.widget.TextView[@text='Contacts']")).click();
driver.findElement(By.id("com.salesforce.chatter:id/new_button")).click();
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Create Contact Heading')]/..//android.view.View[contains(@content-desc,'Phone')]/../android.widget.EditText")).click();
driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Create Contact Heading')]/..//android.view.View[contains(@content-desc,'Phone')]/../android.widget.EditText")).sendKeys("5109651200");
driver.hideKeyboard();
driver.scrollTo("Mobile");
driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Create Contact Heading')]/..//android.view.View[contains(@content-desc,'Mobile')]/../android.widget.EditText")).click();
driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Create Contact Heading')]/..//android.view.View[contains(@content-desc,'Mobile')]/../android.widget.EditText")).sendKeys("6509651200");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterTest
public void End() {
driver.closeApp();
driver.quit();
}
}
我也尝试使用 TouchAction 将文本发送到 Mobile 字段,如下所示。在 appium 日志中显示成功,但在移动页面上既没有点击也没有输入。
driver.swipe(200, 1140, 250, 600, 4000);
WebElement we = driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Mobile')]/..//android.widget.EditText"));
TouchAction touchAction = new TouchAction(driver);
touchAction.press(we);
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
boolean displayed = we.isDisplayed();
System.out.println("Displayed :" + displayed);
we.click();
driver.findElement(By.xpath("//android.view.View[contains(@content-desc,'Mobile')]/..//android.widget.EditText")).sendKeys("6509651200");
【问题讨论】:
标签: java android selenium appium