Monday, November 24, 2014

How to attach screen shot to Testng report

  • If we can attach these to the Testng html report, it provides an option for the user to better analyze the failure reason. Reporter class allows logging messages to the html report. We can use the same class to attach the screen shots as a hyperlink in the report.
Reporter.log("<a href=" + URL+ ">click to open screenshot</a>");
                 URL – location on either local or network drive

  • TestNG you can generate 2 types of report. (Custom TestNg Report )

       1. By implementing ITestListener you can generate a real time reporter where                              individual test case pass/fail status can be displayed in realtime.
       2. By implementing  IReporter you can generate a beautifully designed report that will be              generated once all the test suites have been executed.
http://seleniumexperience.wordpress.com/2013/07/25/generating-custom-reports-with-testng/
https://www.packtpub.com/books/content/logging-and-reports

Sunday, November 23, 2014

Verify CSS (font, background color, etc) using selenium WebDriver


driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);

Error Collector in TestNg


  • Assert will stop its execution on test failure but it is must instead for better automation we have to use it as maximum as possible. 

                          If needs to pass the test 

                          try{ 
                                  Assert.assertequals(true,false); 
                              }
                           catch(Throwable ex){ 
                                   System.out.println("The case will pass"); 
                              } 

              but here u wont get the case marked failed



  • Use try catch, when test case fails, inside catch write "throw new RuntimeException();" so that it will capture in the TestNG report as fail
  • TestNG has support for custom listeners, which can run when tests pass/fail/skip, as well as before and after invocation. By adding a custom listener to check for verification failures after invocation, we can get the details of all verification failures that have occurred, and report them at the same time as we report our hard failure, or if there are no hard failures we can change the result to a failure and report the verification failures.

          This solution uses part of the TestNG soft failures patch by Dan Fabulich in order to combine the stack                 traces of multiple failures. Details of the patch are available here.

  • Class ErrorCollector :-The ErrorCollector rule allows execution of a test to continue after the first problem is found (for example, to collect _all_ the incorrect rows in a table, and report them all at once):

package myWorkjUnit; 
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
 
public class UsesErrorCollectorTwice {
 /*
 * The ErrorCollector Rule allows execution of a test to continue after the
 * first problem is found and report them all at once
 */
 @Rule
 public ErrorCollector collector= new ErrorCollector();
 
@Test
 public void example() {
 collector.addError(new Throwable("first thing went wrong"));
 collector.addError(new Throwable("second thing went wrong"));
 
 // all lines will run, and then a combined failure logged at the end.
 }
 
}


Thursday, November 20, 2014

Reference sites for FQA on Webdriver


WebDriver:
https://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
http://www.studyselenium.com/2013/12/100-selenium-interview-questions.html
http://www.toolsqa.com/selenium-webdriver/selenium-interview-questions-part-1/

https://docs.google.com/document/d/1VWrD608H3tQCxWzfHsAfFb_Tx8BYUMj-K8Cffy_60mc/edit?usp=sharing


JavaScripExecutor
http://www.mythoughts.co.in/2013/02/executing-javascript-using-selenium.html#.VG7pR_mUdhx

Grid
http://qtp-help.blogspot.in/2011/08/selenium-grid-for-browser-compatibility.html