[Cucumber][Java] Get failed steps to upload to test rail

717 views
Skip to first unread message

Son Phan

unread,
Nov 7, 2016, 7:55:22 AM11/7/16
to Cukes
Hello everyone,

  Currently, i got issue to get failed steps to upload to test rail . I also try to parse cucumber.json to get steps with afterward hook but it was empty at that time. Could you please help me on this?

Thanks,
Son Phan

Andrew Premdas

unread,
Nov 7, 2016, 9:50:22 AM11/7/16
to cu...@googlegroups.com
Son,

This question makes no sense at all. You need to explain your problem clearly and with sufficient detail if you want to get help.

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Son Phan

unread,
Nov 7, 2016, 10:52:25 AM11/7/16
to Cukes
Andrew,

  I have two issues as below

  1.   I try to get failed steps from cucumber to upload result to test rail. For example,
    • I launch the site
    • Input username and password
    • Click on button "Login" <- Failed at this step but i did not know failed reason for this step such as element is not located. Then i used code below to get failed steps
               @After({"@Login"})
             public void afterScenario(Scenario scenario) throws MalformedURLException, IOException, APIException, ParseException{

              if (scenario.isFailed())
{
Do something to get failed reason here
}
else{
       //System.out.println("Check this and upload result to test rail");
      // upload.upload_resultAPI("Passed",testcaseId,null);
}
            }
         
       2. I tried to parse cucumber.json to get failed reason with code below but json file was not written completely and i got issue with end of file.
    @After({"@Regression"})
    public void afterScenario(Scenario scenario) throws MalformedURLException, IOException, APIException{
     if (scenario.isFailed())
{
Do something to parse cucumber.json file
}
else{
        //System.out.println("Check this and upload result to test rail");
       // upload.upload_resultAPI("Passed",testcaseId,null);
}

   }

  Do you know how to force cucumber to write result to json file scenario by scenario after it's finished running? Feel free to check and get back to me if any.

  Thanks,
Son Phan

Vào 21:50:22 UTC+7 Thứ Hai, ngày 07 tháng 11 năm 2016, apremdas đã viết:
Son,

This question makes no sense at all. You need to explain your problem clearly and with sufficient detail if you want to get help.

All best

Andrew
On 7 November 2016 at 09:34, Son Phan <phanvans...@gmail.com> wrote:
Hello everyone,

  Currently, i got issue to get failed steps to upload to test rail . I also try to parse cucumber.json to get steps with afterward hook but it was empty at that time. Could you please help me on this?

Thanks,
Son Phan

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Roberto Lo Giacco

unread,
Nov 9, 2016, 12:58:03 PM11/9/16
to Cukes


Il giorno lunedì 7 novembre 2016 16:52:25 UTC+1, Son Phan ha scritto:
Andrew,

  I have two issues as below

  1.   I try to get failed steps from cucumber to upload result to test rail. For example,
    • I launch the site
    • Input username and password
    • Click on button "Login" <- Failed at this step but i did not know failed reason for this step such as element is not located. Then i used code below to get failed steps

The reason why the test failed is not in scope for Cucumber.... In this example, since youa re talking about buttons and elements, I'm guessing you are using Selenium. I've faced your same issue in the past and developed a little library (called SmartUnit available on github) which helps me identify the missing element. please rememebr Cucumber has nothing to share with testing, it's an executor for specifications expressed in the Gherkin language. This is a common misunderstanding and I've wrote a short post on my blog trying to clarify the difference.

 
               @After({"@Login"})
             public void afterScenario(Scenario scenario) throws MalformedURLException, IOException, APIException, ParseException{

              if (scenario.isFailed())
{
Do something to get failed reason here
}
else{
       //System.out.println("Check this and upload result to test rail");
      // upload.upload_resultAPI("Passed",testcaseId,null);
}
            }

I believe your misunderstanding here is about the isFailed() method semantics: a scenario fails if any of the steps in the scenario fails, but failure here stands for execution failure, not test verification failure. What you are looking for is for the reason the test verification failed, but Cucumber delegates this to whatever tool you decide to use, in your case Selenium, probably.
 
         
       2. I tried to parse cucumber.json to get failed reason with code below but json file was not written completely and i got issue with end of file.
    @After({"@Regression"})
    public void afterScenario(Scenario scenario) throws MalformedURLException, IOException, APIException{
     if (scenario.isFailed())
{
Do something to parse cucumber.json file
}
else{
        //System.out.println("Check this and upload result to test rail");
       // upload.upload_resultAPI("Passed",testcaseId,null);
}

   }

All you can extract from Cucumber at this stage is the step which failed in the scenario, but you don't need to parse the JSON file to do so. Also, trying to read a file while it is being written can lead to unexpected results, as you have discovered yourself.
 

  Do you know how to force cucumber to write result to json file scenario by scenario after it's finished running? Feel free to check and get back to me if any.

This is not going to help you, unless the information you are looking for is going to be within the JSON file after all the scenarios have been executed, which I believe it's not the case.

Roberto

Son Phan

unread,
Nov 10, 2016, 4:54:10 AM11/10/16
to Cukes
Thank for your explanation, Roberto. Please see my response in-line.

Vào 00:58:03 UTC+7 Thứ Năm, ngày 10 tháng 11 năm 2016, Roberto Lo Giacco đã viết:


Il giorno lunedì 7 novembre 2016 16:52:25 UTC+1, Son Phan ha scritto:
Andrew,

  I have two issues as below

  1.   I try to get failed steps from cucumber to upload result to test rail. For example,
    • I launch the site
    • Input username and password
    • Click on button "Login" <- Failed at this step but i did not know failed reason for this step such as element is not located. Then i used code below to get failed steps

The reason why the test failed is not in scope for Cucumber.... In this example, since youa re talking about buttons and elements, I'm guessing you are using Selenium. I've faced your same issue in the past and developed a little library (called SmartUnit available on github) which helps me identify the missing element. please rememebr Cucumber has nothing to share with testing, it's an executor for specifications expressed in the Gherkin language. This is a common misunderstanding and I've wrote a short post on my blog trying to clarify the difference.
 
 [SonP] Can you share the link of SmartUnit github?

 
               @After({"@Login"})
             public void afterScenario(Scenario scenario) throws MalformedURLException, IOException, APIException, ParseException{

              if (scenario.isFailed())
{
Do something to get failed reason here
}
else{
       //System.out.println("Check this and upload result to test rail");
      // upload.upload_resultAPI("Passed",testcaseId,null);
}
            }

I believe your misunderstanding here is about the isFailed() method semantics: a scenario fails if any of the steps in the scenario fails, but failure here stands for execution failure, not test verification failure. What you are looking for is for the reason the test verification failed, but Cucumber delegates this to whatever tool you decide to use, in your case Selenium, probably.
 [SonP] Can we do something to get failed from selenium and put to here? 

Roberto Lo Giacco

unread,
Nov 11, 2016, 6:36:19 PM11/11/16
to Cukes

Il giorno giovedì 10 novembre 2016 10:54:10 UTC+1, Son Phan ha scritto:
Thank for your explanation, Roberto. Please see my response in-line.

The reason why the test failed is not in scope for Cucumber.... In this example, since youa re talking about buttons and elements, I'm guessing you are using Selenium. I've faced your same issue in the past and developed a little library (called SmartUnit available on github) which helps me identify the missing element. please rememebr Cucumber has nothing to share with testing, it's an executor for specifications expressed in the Gherkin language. This is a common misunderstanding and I've wrote a short post on my blog trying to clarify the difference.
 
 [SonP] Can you share the link of SmartUnit github?

 
I believe your misunderstanding here is about the isFailed() method semantics: a scenario fails if any of the steps in the scenario fails, but failure here stands for execution failure, not test verification failure. What you are looking for is for the reason the test verification failed, but Cucumber delegates this to whatever tool you decide to use, in your case Selenium, probably.
 [SonP] Can we do something to get failed from selenium and put to here? 

My choice is to have selenium generate an exception and let that pass through: it ends up being part of the scenario failure condition in the reports (I use HTML report, but it is generated upon the JSON one)
Reply all
Reply to author
Forward
0 new messages