[英]WebDriver C# extension methods in Java
In C# I would write extension methods to add functionalities to IWebDriver and IWebElement. 在C#中,我将编写扩展方法以向IWebDriver和IWebElement添加功能。
Example: 例:
public static IWebElement ClearAndSendKeys(this IWebElement e, string text)
{
e.Clear();
e.SendKeys(text);
}
I would use this later then like this: 我会在以后这样使用:
txtUsername.ClearAndSendKeys("user123");
I've changed job recently and in the new company I am writing tests in Java. 我最近换了工作,在新公司里我用Java编写测试。 So far I have been banging my head against the wall trying to figure out the best way to at least get something close to what I was doing in C#.
到目前为止,我一直在摸索,试图找出最好的方法,以使至少能达到我在C#中所做的事情。 Suggestions?
建议?
Java does not support extension methods, period. Java不支持扩展方法,句点。 You can create static methods instead:
您可以改为创建静态方法:
ClearAndSendKeys(txtUsername, "user123");
(using static method imports) (使用静态方法导入)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.