The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Selenium UnreachableBrowserException - “Could not start a new session”

Some time selenium unable to reached the browser and through some exception : "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'SmithPC', ip: '10.0.2.15', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:171)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:160)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

To resolve this you have to do only small changes in the host file.


Host file Location : C:\Windows\System32\drivers\etc

In your host file you have to add localhost entry, as i mention below then run your Selenium or Testng code and check it will work fine.

127.0.0.1            Localhost


I am encounter the same problem, after a long search will found this solution and it worked for me, I hope it will work for you also. 

How to Convert String Date into Millseconds

In your project you have some date and as project requirement you want to convert it into milliseconds or while code you need to convert date into other format, I am same date in file saving, long date is used in file name but it use depend on the developer.


1) First convert string to java.Date using simpledateformatter
2) Use getTime method to obtain count of millisecs from date

public class test {
    public static void main(String[] args) {

         String currentDate = "01-March-2016";
         SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy");
         Date parseDate = f.parse(currentDate);
         long milliseconds = parseDate.getTime();
    }
}

Preserver order in testng as true

you have an web-application and for which you wrote automation script. and in your automation script all the Methods and Class depend on other then  you want to execute your testcases in sequence for sequential execution you have to use "preserve-order" text and its attribute value as
true in testng xml file.

preserve-order is default attribute as true then class and methods should be executed in sequence
TestNG will run all methods and Class in the order as we defined in the sequence in XML file.

in our example we have three class and each class content two methods and we will try to execute the same.

we have below classes.
========================================================================
includeExculde.java

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {
  @Test
  public void testingOne() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingTwo() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}
========================================================================
test_second.java
package testng_Example;
import org.testng.annotations.Test;
public class test_second {
@Test
 public void testingone() {
  System.out.println("======= test_second Class Test one is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
 }
 @Test
 public void testingtwo() {
  System.out.println("======= test_second Class test two is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}
========================================================================
test_three.java
package testng_Example;
import org.testng.annotations.Test;
public class test_three {
@Test
 public void testingthird1() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
@Test
 public void testingthird2() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}

Now we will define the xml file with preserve-order attribute for tests and set the value as 'false'.
<TestngCode> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test" preserve-order="true">
    <classes>
   <class name="testng_Example.includeExculde"/>
        <class name="testng_Example.test_second"/>
       <class name="testng_Example.test_three"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

</testngCodeend>

=============================================================
we have set the preserve-order attribute as ture and now will see the execution in order. They will get executed in an predictable order of class


[TestNG] Running:
  C:\Users\workspace\Blogger_Example\testng.xml

======= includeExculde Class is executed and pass for TestNG ======testingOne
======= includeExculde Class is executed and pass for TestNG ======testingTwo
======= test_second Class Test one is executed and pass for TestNG ======testingone
======= test_second Class test two is executed and pass for TestNG ======testingtwo
======= test_three Class is executed and pass for TestNG ======testingthird1
======= test_three Class is executed and pass for TestNG ======testingthird2

===============================================
Suite
Total tests run: 6, Failures: 0, Skips: 0
===============================================


Preserver order False in Test NG

you have an web-application and for which you wrote automation script.
you have an independent Methods and Class which you want to execute at random or unpredictable order then you have to use "preserve-order" text and its attribute value has to be false in your testng xml file but if you want to execute your method in sequence then set "preserve-order" as true

preserve-order default attribute is true you do not have set it forcefully
TestNG will run your tests in the order they are found in the XML file.

in our example we have three class and each class content two methods and we will try to execute the same. initials we will set preserve-order attribute as false and will check the out-put

we have below classes.
=============================================================================
includeExculde.java

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {
  @Test
  public void testingOne() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingTwo() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}
========================================================================
test_second.java
package testng_Example;
import org.testng.annotations.Test;
public class test_second {
@Test
 public void testingone() {
  System.out.println("======= test_second Class Test one is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
 }
 @Test
 public void testingtwo() {
  System.out.println("======= test_second Class test two is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}
========================================================================
test_three.java
package testng_Example;
import org.testng.annotations.Test;
public class test_three {
@Test
 public void testingthird1() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
@Test
 public void testingthird2() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}

Now we will define the xml file with preserve-order attribute for tests and set the value as 'false'.
<Code View><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test" preserve-order="false">
    <classes>
      <class name="testng_Example.test_three"/>
      <class name="testng_Example.test_second"/>
      <class name="testng_Example.includeExculde"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
</Code View End>

we have set the preserve-order attribute as false and now will see the execution in order. They will get executed in an unpredictable order of class

[TestNG] Running:
  C:\Users\ankitjain\AppData\Local\Temp\testng-eclipse--706368730\testng-customsuite.xml

======= includeExculde Class is executed and pass for TestNG ======testingOne
======= includeExculde Class is executed and pass for TestNG ======testingTwo
======= test_second Class Test one is executed and pass for TestNG ======testingone
======= test_second Class test two is executed and pass for TestNG ======testingtwo
======= test_three Class is executed and pass for TestNG ======testingthird1
======= test_three Class is executed and pass for TestNG ======testingthird2



Include and Exclude Java method on TestNG

TestNg provides an options to include or exclude Groups, Java class, Java methods using include and exclude tags in XML file.

Below is the example which give you how to user include and exclude tags for methods.
Let as take an example : if you have a class which contents 5 or 6 java method in which you want to executed only two method and remaining method does not execute know.

I will create a Java class which contents five methods, in which we will include two methods and remaining three would be exclude.

Below is the example class file with three test methods

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {

  @Test
  public void testingFrist() {
  System.out.println("======= which Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingSecond() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingThird() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFourth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFifth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}

In the above example, we have created five methods, 'testingFirst','testingSecond','testingThird','testingFourth' and 'testingFifth'

In testng.xml file we will include "testingFirst","testingSecond" and "testingFourth" and exclude "testingThird" & "testingFifth" and try to execute the same using testng.xml and it will execute the Three class and does not execute two classes. Methods always define inside class tag.




How to Verify Checked & Unchecked of check-Box Using selenium Webdriver

Checkbox are an often used element in the web application, But how do you work with them in selenium web driver or automation testing.
I am doing an automation testing of one application and I am facing one scenario to verify Check-box are checked or not using automation code

Solution :
There are two ways to approach this first one check if an element has a checked attribute or not, Checked attribute you can check in fire-bug for particular checkbox(a.k.a. performing an attribute lookup), another one by asking an element has been selected or not, you can check selected or isselected using webdriver inbuilt method


Below is CSS code to verify checked and unchecked attribute:


  unchecked
  checked

Java Code :

public void VerifyChkbox(WebElement chkbox){
boolean checkstatus;
checkstatus=chkbox.isSelected();
if (checkstatus==true){
System.out.println("Checkbox is already checked");  
       }
else
     {
chkbx1.click();
System.out.println("Checked the checkbox");
     }
}

Same code is applicable for unchecked


Powered by Blogger.