My Thoughts: TestNG
Showing posts with label TestNG. Show all posts
Showing posts with label TestNG. Show all posts

Monday, November 26

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

 I am using selenium 2.24 jar files.But today , I got below errors when I ran one of my sample script.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\vkurra\AppData\Local\Temp\anonymous4553384920216924839webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\vkurra\AppData\Local\Temp\anonymous4553384920216924839webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found


Immidiate thing I have done is , selenium jars updation. I have downloaded latest selenium 2.25 jars and added them to my project buildpath. Now things are going smooth :)

Saturday, August 18

WebDriver Tutorial Part 4 : Working with TestNG framework in Eclipse


Writing a script in plain Java is simple like what we have done in the previous post. But there is more we can do using WebDriver.

Say If you want to run multiple scripts at a time ,better reporting and you want to go for datadriven testing (Running the same script with multiple data) then plain Java script is not enough .

So it is recommended to use any of the existing frameworks like TestNG or JUnit. Select one of the framework and start using it.

In this post , I start with TestNG. If you are planning to use TestNG then you need to
  • 1.Install TestNG Eclipse plug-in 
  • 2.Customize the output directory path
  • 3.Start writing scripts
1.Install TestNG Eclipse plug-in 

Detailed instruction on how to install TestNG plug-in can be found here

2.Customize the output directory path

This is not a mandatory step. But it is good to have it.Using this you can tell TestNG where to store all the output results files. 

In Eclipse Goto Window>>Preferences>>TestNG>>
Set the Output Direcory location as per your wish and click on "Ok".

Vamshi Kurra -TestNG

3.Start writing scripts
Writing scripts using TestNG is so simple. We will start with the editing of script we have written in the previous post .
Here is the edited script using TestNG.
package learning;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GoogleSearchTestNG {

 WebDriver driver;
 
 @BeforeTest
 public void start(){
  driver = new FirefoxDriver();
 }
 
 @Test
 public void Test(){ 
  System.out.println("Loading Google search page");
  driver.get("http://google.com");
  System.out.println("Google search page loaded fine");
 }
 
 @AfterTest
 public void close(){
  driver.quit(); 
 }
}

If you look at the above code the main chnages we have done is 
1.Imported new TestNG files

2.Now there is no main function.We removed it.

3.We have split the single main function into 3 functions. i.e start(), test(), close()
start()  -- Initialize the WebDriver
Test()  -- Perform our exact requirement.
close() -- Close the Browser once

4.There are 3 different annotations named "BeforeTest" , "Test" , "AfterTest".
@BeforeTest -- Keep this annotaion before a method which has to be called initially when you run the script. In our script ,we put it before start() method because we want to initialize the WebDriver first.
@Test    -- Keep this annotation before a method which will do the exact operation of your script.
@AfterTest -- Keep this annotation before mehod which has to run at the end. In our script , closing browser has to be done at the end. So we put this annotation before close() method.

TestNG is so powerful . But now we stop here :) and experiment more on WebDriver functions. Once that is done we will come back to TestNG.

Can't wait and learn more ?? , you can always refer documents here

Going forward all the example scripts in this site will refer to TestNG.

Thursday, May 10

TestNG XMLfile preparation and error messages


Here is the sample TestNG file :

  
  
   
               
        
     
   
   
           
        
     
   


It is also important to know about error messages.Sometimes we learn more from errors :)
I have put some of the error messages we get when we go wrong in the above TestNG XML file .

Here are the error codes we will see when we have done any error in the above XML file.

1.If two tests are having the same name then we see below error
Ex :  
<test name="Testing the Google"> 
        <classes>       
        <class name="com.google.UI"/>
     </classes>
  </test> 
  <test name=" Testing the Google "> 
    <classes>       
        <class name="com.google.gmail"/>
     </classes>
  </test> 
Two tests in the same suite cannot have the same name: <<Test anme>>
at org.testng.TestNG.checkTestNames(TestNG.java:981)
at org.testng.TestNG.sanityCheck(TestNG.java:970)
at org.testng.TestNG.run(TestNG.java:1002)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)

2.If the testname doesnot elclosed in double quotes("") then we wills ee below error
Ex :  <test name=Testing the Google> 
The value of attribute "name" associated with an element type "null" must not contain the '<' character.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: The value of attribute "name" associated with an element type "null" must not contain the '<' character.
atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

3.If the class name doesnt end with "/" character then we will see below error
org.testng.TestNGException: org.xml.sax.SAXParseException: The end-tag for element type "class" must end with a '>' delimiter.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: The end-tag for element type "class" must end with a '>' delimiter.

4. If there is no space between parameter name and value  fields then we will see below error 
Ex   :  <parameter name="googleURL"value="http://google.com"/>
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "parameter" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "parameter" must be followed by either attribute specifications, ">" or "/>".

5.If the parameter attribute doesnt end with "/" character then we will see below error
Ex   :  <parameter name="googleURL"value="http://google.com">
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".


6. If the two parameters have the same name and value attributes then we will see below error
Ex   :  <parameter name="googleURL"value="http://google.com"/>
          <parameter name="googleURL"value="http://google.com"/>
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".

7.Make sure there are no spaces between "/" and  ">".If there are any spaces then we will see below error.
Ex   :  <parameter name="googleURL"value="http://google.com"/                >
org.testng.TestNGException: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: Element type "class" must be followed by either attribute specifications, ">" or "/>".

Tuesday, May 1

TestNG : The reference to entity "tab" must end with the ';' delimiter.


Today I have faced problem while running the below TestNg XML file .

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="testing test suite">
  <parameter name="googlePlayUrl" value="https://play.google.com/store?hl=en&tab=w8"/>
  <test name="checking the Google play">
    <classes>
       <class name="com.google.play.UrlVerification"/>
    </classes>
  </test>
</suite>

When I run the above TestNG XML file I got bellow error

org.testng.TestNGException: org.xml.sax.SAXParseException: The reference to entity "tab" must end with the ';' delimiter.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:335)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: The reference to entity "tab" must end with the ';' delimiter.

Solution to the above problem is very simple. Replace the "&" symbol with "&amp;"

I have changed my XML file like below and it was successed.

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="testing test suite">
  <parameter name="googlePlayUrl" value="https://play.google.com/store?hl=en&amp;tab=w8"/>
  <test name="checking the Google play">
    <classes>
       <class name="com.google.play.UrlVerification"/>
    </classes>
  </test>
</suite>