I have written cucumber tests with selenium framework. When my test ran in sequential they all pass, but when I run in parallel they fail because the same user is used for all the tests and the test is to login to app, change the language and verify the language, logout and log back in to verify the language for that user is persistent.
The issue is each test is to verify different language. So, the test 1 runs and during logout and log back in the second test already running and it changed the language. due to that the test 1 fails as the language is not same. For that I read online that using hooks might help in running test scenarios sequentially in parallel test. I did implement the hooks but still they are not working. Not sure if I am doing this correct.
Here is my feature file
@Profile @VerifyLanguageSetPortugues
Scenario Outline: Profile tests(Verify App Languages selection Espanol)
Given "guest" user login to app "DARTTS" using "AppAuth"
Then I verify previous language setting is active from app title "<Current AppTitle>"
And I click on language "<Language>"
Then I verify selected language for "<Field1>" "<Field2>" "<Field3>"
And I logout and log back in
And I verify previous language setting is active from app title "<Previous AppTitle>"
When I click on user profile button
Then I should log out of Raven app
Examples:
| Language | Current AppTitle | Previous AppTitle | Field1 | Field2 | Field3 |
| Português | Analyze | Analisar | Clique no botão "novo grupo de filtros" para criar seu primeiro grupo de filtros. | Selecione um filtro para mostrar os resultados nesta tela. | Expandir explorar e tabular as estatísticas |
@Profile @VerifyLanguageSetEspanol
Scenario Outline: Profile tests(Verify App Languages selection Espanol)
Given "guest" user login to app "DARTTS" using "AppAuth"
Then I verify previous language setting is active from app title "<Current AppTitle>"
And I click on language "<Language>"
Then I verify selected language for "<Field1>" "<Field2>" "<Field3>"
And I logout and log back in
And I verify previous language setting is active from app title "<Previous AppTitle>"
When I click on user profile button
Then I should log out of Raven app
Examples:
| Language | Current AppTitle | Previous AppTitle | Field1 | Field2 | Field3 |
| Español | Analyze | Analizar | Haga clic en el botón "nuevo grupo de filtros" para crear su primer grupo de filtros. | Seleccione un grupo de filtros para mostrar los resultados en esta pantalla. | Ampliar la exploración y las estadísticas de las columnas |
Hooks class
public class Hooks {
@Before(order = 1, value = "@VerifyLanguageSetPortugues")
public void portuguesLangBeforeScenario() {
System.out.println("This should run first");
}
@After(order = 1, value = "@VerifyLanguageSetPortugues")
public void portuguesLangAfterScenario() {
System.out.println("This should end first");
}
@Before(order = 2, value = "@VerifyLanguageSetEspanol")
public void espanolLangBeforeScenario() {
System.out.println("This should run second");
}
@After(order = 2, value = "@VerifyLanguageSetEspanol")
public void espanolLangAfterScenario() {
System.out.println("This should end second");
System.out.println("Espanol language is set to true");
}
In the output I see the messages are printed right next to each message. The second scenario didn’t wait until the first one is completed.
11:01:59.545 [TestNG-PoolService-1] INFO gov.dhs.ice.raven.resources.base - Detected Dartts scenario tag.
11:02:05.474 [TestNG-PoolService-0] INFO gov.dhs.ice.raven.resources.base - WebDriver setup is complete
This should run first
11:02:05.548 [TestNG-PoolService-1] INFO gov.dhs.ice.raven.resources.base - WebDriver setup is complete
This should run second