[英]Java8 with Selenium WebDriver
I am new to Java-8
and appium and trying to write my webdriver code in Java-8
as mentioned below 我是
Java-8
和appium的新手,并尝试在Java-8
编写我的webdriver代码,如下所述
Currently below code is working fine but I don't want to write Function and Consumer in separate lines as mentioned below in lines line 5 and line 6 and i want to optimize the code more ie something like Function within Consumer or Consumer within Function.Thanks! 目前下面的代码工作正常但我不想在单独的行中编写函数和消费者,如下面第5行和第6行所述,我想更多地优化代码,例如消费者中的函数或函数内的消费者。谢谢! in Advance
提前
public class Gestures_Drag_And_Drop {
AndroidDriver<AndroidElement> driver;
Function<String, AndroidElement> F = driver::findElementByXPath;//line 5
Consumer<AndroidElement> C = AndroidElement::click; //line 6
Gestures_Drag_And_Drop() {
C.accept(F.apply("//android.widget.TextView[@text='Views']"));
}
public static void main(String[] args) throws MalformedURLException {
new Gestures_Drag_And_Drop();
}
}
Your function or consumer variable not need to be just method reference, you can define whatever method body you want using lambda expressions. 您的函数或使用者变量不需要只是方法引用,您可以使用lambda表达式定义所需的任何方法体。 I guess you asking for something like this:
我想你要求这样的东西:
BiConsumer<String, WebDriver> findAndClick = (locator, webdriver) -> webdriver.findElement(By.xpath(locator)).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.