Once I created a web testing framework, which is actually a wrapper for Selenium, for a company that works with JSF.
The problem with JSF is exactly the one pointed out by Elias in the first item on the list: it generates dynamic Ids for many elements. This makes it impossible for Firefox’s Selenium IDE to always run the same way.
For example, if you do not set an ID for any page element, JSF will take care of it. A button on a form, for example, can end up as the id meuFormulario:j_id45674
(this can change from one run to another) and a field in a datatable tabela:0:nomeCampo
(it doesn’t change, but it’s hard to work).
To get around these problems, the solution was to use CSS and Xpath selectors using the attribute name
for form fields and other attributes for images.
Finally, the solution I found was to create such a framework that, among other things, provided some methods that encapsulated selectors for the company’s standard components.
For example, every inclusion record had a button with a specific class attribute, for example, botao-incluir
. In other cases, the button contained a specific image. So I created a class that all test classes could extend or import statically and use more or less like this (in Java):
public class CadastroCliente extends TestBase {
@Test
public void cadastrarCliente() {
type(campo("nome"));
type(campo("idade"));
click(botaoIncluir());
aguardar();
}
}
In JSF, the field nome
, for example, could have the ID generated as formCad:panel10:nome
. So the method campo()
would actually return a selector like this:
css=input[id$=':nome']
The above selector is a CSS selector that searches for an element input
on the page whose ID ends with :nome
.
The methods type
and click
that are in the sample code are Wrappers of Selenium that I made specially adapted to the system in question.
The advantage of abstracting Selenium’s original methods is that there was often some specific behavior that required special treatment. In this case, I simply adjusted the Wrapper class without touching the tests.
The method aguardar()
, for example, you can automatically do checks on validation errors, that is of course, if there is a pattern followed throughout the system.
Face the page is fully loaded you understand, but the reference of some elements is wrong. I do not know why they change. And when you have a
comboBox
use theTab
it does not select, only through theclick
. I’ll read what you posted. Thank you– Macario1983