当Appium&Selenium脚本要在真实的移动设备上执行时,我想使用JavascriptExecutor进行突出显示。但遇到了一些问题。
我们还可以将JavascriptExecutor用于Appium脚本吗?如果可以,您可以指导我吗?
public class HighlightTesting {
AndroidDriver<MobileElement> driver = null;
ObjectRepository or;
@Test
public void sslWebApp() throws Exception {
String workspace=System.getProperty("user.dir");
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samba");
caps.setCapability("udid", "28a950650404"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.0");
caps.setCapability("noReset", true);
caps.setCapability("autoGrantPermissions", true);
caps.setCapability("appPackage", "shoppersstop.shoppersstop");
caps.setCapability("appActivity","com.shoppersstop.apps.ui.splash.SplashActivity");
driver = new AndroidDriver<MobileElement> (new URL("http://127.0.0.1:4723/wd/hub"), caps);
Thread.sleep(5000);
new BaseClass(driver);
JavascriptExecutor jse = (JavascriptExecutor) driver;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Welcome to Shoppersstop mobile App");
WebElement el=driver.findElement(By.xpath("(//*[@resource-id='shoppersstop.shoppersstop:id/imageview_circular_widget_item'])[3]"));
jse.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", el);
driver.quit();
System.out.println("Done");
}
}
答案 0 :(得分:0)
这种突出显示元素的方式仅适用于:
查看以下几行:
caps.setCapability("appPackage", "shoppersstop.shoppersstop");
caps.setCapability("appActivity","com.shoppersstop.apps.ui.splash.SplashActivity");
似乎您正在测试本机Android应用程序,因此您只能使用Mobile Commands,Appium本机支持,最终可以通过SeeTest - Appium Extensions来获得一些额外功能
如果您需要测试定位器,则可以使用Appium Desktop或Layout Inspector或Appium Studio或Android Device Monitor