1

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?

RealHowTo
  • 34,977
  • 11
  • 70
  • 85
Prostak
  • 3,565
  • 7
  • 35
  • 46

1 Answers1

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();
    }
}
tehlexx
  • 2,821
  • 16
  • 29
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • Even though your code works, it can be truncated even further: win = baseState.execute(desktop).find("//BrowserWindow"); app could be removed completely. Would you like to modify your post? – Prostak Apr 29 '11 at 19:50