我有以下代码:
public class Search {
private Desktop desktop = new Desktop();
@Before
public void baseState() {
BrowserBaseState baseState = new BrowserBaseState("silk4j.settings");
baseState.execute(desktop);
}
@Test
public void searchNames() {
desktop.<BrowserApplication>find("//BrowserApplication").<BrowserWindow>find("//BrowserWindow").<DomButton>find("//INPUT[@id='edit-submit']").select();
}
}
我能够将Test方法截断为:
public class Search {
private Desktop desktop = new Desktop();
BrowserApplication app;
@Before
public void baseState() {
BrowserBaseState baseState = new BrowserBaseState("silk4j.settings");
app = baseState.execute(desktop);
}
@Test
public void searchNames() {
app.<BrowserWindow>find("//BrowserWindow").<DomButton>find("//INPUT[@id='edit-submit']").select();
}
如何进一步截断方法?我希望能够使用这样的东西:
win.<DomButton>find("//INPUT[@id='edit-submit']").select();
而不是这个粗短的:
desktop.<BrowserApplication>find("//BrowserApplication").<BrowserWindow>find("//BrowserWindow").<DomButton>find("//INPUT[@id='edit-submit']").select();
请将整个课程粘贴到您的回复中吗?
答案 0 :(得分:2)
public class Search {
private Desktop desktop = new Desktop();
BrowserWindow win;
@Before
public void baseState() {
BrowserBaseState baseState = new BrowserBaseState("silk4j.settings");
win = baseState.execute(desktop).find("//BrowserWindow");
}
@Test
public void searchNames() {
win.<DomButton>find("//INPUT[@id='edit-submit']").select();
}
}