How to generate testNG report with assert pass or fail information - selenium-webdriver

Hi I have a testNG class with Assert.assertTrue(true, "PASS"); and Assert.assertFalse(false, "FAIL"); statements. After the execution I am not able to find these PASS and FAIL result in the HTML report generated. I googled and found these may not be displayed in the report generated. So my question is, if testNG report does not provide this feature, is there any other reporting with which I can find these data after execution of my test in my report?

To log the information from the script to the HTML report we must use the class org.testng.Reporter. Now to print the data to the report we must use Reporter.log("PASS/FAIL");.

if you use Assert.assertTrue(condition, message); then when the condition is fail means it does not returns true, then the message is printed. So if assertion is true or pass then message is not printed.
To customize the HTML reports in TestNG, you need to use TestNG Listeners. below link will help you
http://testng.org/doc/documentation-main.html#logging-reporters
Let me know, if it is what you looking for.
Thank You,
Murali

If you want to fail the same Test case then you need to add Assert.fail() in your test case. Then it will display as fail in your report.

Related

Salesforce developer console - APEX runner

I am trying to run code in the developer console. From the "execute anonymous window". How do i access the case written in the console from the child window.
it shows the attached error when trying to execute
I am still getting the same error. screenshot below. Please let me know if the screenshots are visible otherwise i will upload somewhere else.
"Test" is a name of a built-in apex class used when writing unit tests. It's bad idea to name your own classes like the standard ones, it can lead to "fun" scenarios like "integer account = 5; sobject a = new account();"
https://developer.salesforce.com/docs/atlas.en-us.234.0.apexref.meta/apexref/apex_methods_system_test.htm
Make new class with similar body, delete that one and try your code again.
And since your method is static, you can do MyClass.myTest(), you don't need "new"

Using the Python API is there anyway to get the Test Run's Status?

I currently have a python program which exports Test Runs, Test Plans, and Test Cases to CSV.
I am using the TestRun Model but I cannot get the information highlighted in the status column seen here. Is there anyway to get this information?
Thanks!
I currently have a python program which exports Test Runs, Test Plans, and Test Cases to CSV.
This is great. Please consider contributing your script under https://github.com/kiwitcms/api-scripts
I am using the TestRun Model but I cannot get the information highlighted in the status column seen here. Is there anyway to get this information?
Note: these screenshots are old!
There is no TestRun.status field, the status is only a visual property which is calculated by the UI based on the presence or absence of TestRun.stop_date field. If this field is null/None then the status is "Running", otherwise it is "Stopped".
In the current TR search page for example we query the TestRun.filter API with a
stop_date__isnull=True parameter.

Is it possible to use #Issue annotations to impact the category a test appears as inside an Allure report?

Is it possible to use #Issue annotations to impact the category a test appears as inside an Allure report?
I would like tests with an #Issue annotation to show in "Product Defects" and those without to appear in "Test Defects".
#Issue("JIRA-1234")
public void productDefect() {
// Test which fails and should be categorised as product defect
}
The Allure documentation on categories doesn't show a way of doing this. Is there a way of controlling the category based on on the issue annotation or is is exclusively the test error message/stack trace?
If this isn't possible out of the box, is there a workaround to easily achieve this behaviour?
This doesn't appear to currently be possible, but there is an open request for the feature on GitHub.

How to integrate the Reporter.log("Login failed.") with custom testng report using the IReporter?

I have been trying to generate a custom testng report similar to the emailable-report.html which is generated by default in testng. In my test case, I have added reporter.log statement to check the flow of test execution, but these logs are not getting printed in the custom report.
Is there a way to integrate the log statement in the custom report ?
In order for the messages logged via Reporter.log() to show up in your test reports, you would basically need to retrieve them using Reporter.getOutput(result) (Here result is of type org.testng.ITestResult). Invoking this method you would get a list of strings which represents the output associated with that particular ITestResult object. You would need to dump these lines into your report.
For a sample, take a look at this section of the EmailableReporter2.java from TestNG.

Best way to use Assertion in Page Object Model (POM)?

I m Using following assertion to read the validation message in POM but sometimes testcases may give different Validation message which makes TestCase fail , i want to get that Validation message if the testcase fails so that i can debug easily
// Assert whether Account Created Successfully or Not
WebElement element = driver.findElement(By.xpath("//html/body/table[2]/tbody/tr/td/form/table/tbody/tr/td/font"));
String strngAcc = element.getText();
System.out.println(strngAcc);
Assert.assertEquals(" Account Information Created Successfully", strngAcc);
If the Validation got was "Account Already exists" , the Testcase fails indicating that
xpath could not found //html/body/table[2]/tbody/tr/td/form/table/tbody/tr/td/font
i want to capture that validation "Account Already exists" .
please provide me a way to pick the validation actually displaying
PS : I Dont want to go with Screen Shot Capture method
Please don't use xpaths that are too literal in the placement in the html code because by doing this, your tests become brittle and can easily break (e.g. if the structure of the dom changes a bit).
It sounds like the xpath of the correct validation message and "Account Already exists" message are different...What does the structure of the elements look like in html? Again, your xpath may be too specific. Could you give more info?
Your problem isn't the assertion, it's fact that WebDriver cannot find the element it's looking for with that xpath.
Rather than using this absolute XPath, you should look for better ways to find the element you're looking for. Do any of the elements the validation error have specific ID's that you can search for? You'll have to post a snippet of the HTML if you want any more specific help than that.

Resources