截断java中的方法

发布于 2024-11-03 20:15:13 字数 1343 浏览 0 评论 0原文

我有以下代码:

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();

    }

}

我能够将测试方法截断为:

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();

请将整个课程粘贴到您的回复中?

I have the following code:

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();

    }

}

I was able to truncate the Test method to this:

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();

}

How do I truncate the method even further? I would like to be able to use something like this:

win.<DomButton>find("//INPUT[@id='edit-submit']").select();

instead of this chunky long:

desktop.<BrowserApplication>find("//BrowserApplication").<BrowserWindow>find("//BrowserWindow").<DomButton>find("//INPUT[@id='edit-submit']").select();

Please paste the whole class in your response?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-11-10 20:15:13
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();
    }
}
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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文