Coding approach in Appium


I am new to appium learning and trying to write simple code for test automation. One query i have is that when I try to, say, automate the dialing of a number from phone, i can either use layouts like this:

driver=new AppiumDriver(new URL(“”),capabilites);
WebElement linearLayout=driver.findElement(“”));

or I can simply call find element function from AppiumDriver objects like this:

driver=new AppiumDriver(new URL(“”),capabilities); dr.findElement(“”)).click();

My question is that which approach is better in terms of coding best practices? How does use of elements like layout make a difference while writing tests like these?

Exposing the underlying uiautomator code limits your tests to Android only. That may be your goal, but it makes the code less readable. I prefer your second example. I might be tempted to create constants such as DIALER_ONE to replace the id to make it even more readable.

Actually, he is not exposing uiautomator code. He simply named his WebElement linearLayout and then searched its child elements. He could have named it Dialpad as well. Creating WebElements and giving them simple names makes the code more readable, because you don’t have to write the findElementBy… part each time you interact with a given element.



if you previously created a “One” WebElement.