cancel
Showing results for 
Search instead for 
Did you mean: 

How to reduce the length of search pattern in testleft?

Occasional Visitor

How to reduce the length of search pattern in testleft?

IButton button = Driver.Find<IProcess>(new ProcessPattern(){
ProcessName = "S******"
}).Find<ITopLevelWindow>(new WindowPattern(){
WndClass = "Afx:00400000:b*"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxFrameOrView100u",
Index = 2
}).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534B90",
WndCaption = "A*** E****e"
}).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534278"
}).Find<IWindow>(new WindowPattern(){
WndClass = "Shell Embedding"
}).Find<IWindow>(new WindowPattern(){
WndClass = "Shell DocObject View"
}).Find<IWebPage>(new WindowPattern(){
WndClass = "Internet Explorer_Server"
}).Find<IWebPage>(new WebPagePattern(){
URL = "file://***********************.htm*",
ObjectGroupIndex = 0
}).Find<IButton>(new WebElementPattern(){
ObjectType = "Button",
idStr = "p***********002"
}, 3);

button.Click();

1 REPLY 1
Moderator

Re: How to reduce the length of search pattern in testleft?

Hi akila,

 

You can remove intermediate Find calls and add the search depth instead. For example:

 

Before:

IButton button = Driver.Find<IProcess>(new ProcessPattern(){
    ProcessName = "S******"
}).Find<ITopLevelWindow>(new WindowPattern(){
    WndClass = "Afx:00400000:b*"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "AfxFrameOrView100u",
    Index = 2
}).Find<IWindow>(new WindowPattern(){
    WndClass = "ATL:00534B90",
    WndCaption = "A*** E****e"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "ATL:00534278"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "Shell Embedding"
}).Find<IWindow>(new WindowPattern(){
    WndClass = "Shell DocObject View"
}).Find<IWebPage>(new WindowPattern(){
    WndClass = "Internet Explorer_Server"
}).Find<IWebPage>(new WebPagePattern(){
    URL = "file://***********************.htm*",
    ObjectGroupIndex = 0
}).Find<IButton>(new WebElementPattern(){
    ObjectType = "Button",
    idStr = "p***********002"
}, 3);

After:

IButton button = Driver.Find<IProcess>(new ProcessPattern(){
    ProcessName = "S******"
}).Find<ITopLevelWindow>(new WindowPattern(){
    WndClass = "Afx:00400000:b*"
}, 4).Find<IWindow>(new WindowPattern(){
    WndClass = "ATL:00534B90",
    WndCaption = "A*** E****e"
}).Find<IWebPage>(new WebPagePattern(){
    URL = "file://***********************.htm*"
}, 5).Find<IButton>(new WebElementPattern(){
    ObjectType = "Button",
    idStr = "p***********002"
}, 3);

 

You can also use variables to store objects that you are going to re-use in other search patterns:

IProcess myApp = Driver.Find<IProcess>(new ProcessPattern(){ ProcessName = "S******" });

IWebPage page = myApp.Find<ITopLevelWindow>(new WindowPattern(){
WndClass = "Afx:00400000:b*"
}, 4).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534B90",
WndCaption = "A*** E****e"
}).Find<IWebPage>(new WebPagePattern(){
URL = "file://***********************.htm*"
}, 5);

IButton button = page.Find<IButton>(new WebElementPattern(){ ObjectType = "Button", idStr = "p***********002" }, 3);

Helen Kosova
SmartBear Technical Writer
________________________
Join the annual community event and share your stories to win gifts
Wintertainment2019