example of assert

2
Example Of Assert.assertFalse Assertion In Selenium WebDriver With TestNG When you are or!in" ith selenium eb#river$ you must be aare about #i %e rent !i n# of assert io ns hi&h are av ai labl e. If yo u have a enou"h !nole#"e about eb#river assertions$ 'ou &an &reate very e%e&tive test &ases for your test s&enarios. assertE(uals $ assertNotE(uals  an# assertTrue assertions are alrea#y explaine# in my previous posts. No let e try to un#erstan# assertFalse assertion for selenium eb#river. Assert.assertFalse)&on#ition* Assertion It ill &he&! boolean value returne# by &on#ition an# ill pass if returne# value is +False+. If returne# value is pass then this assertion ill fail an# s!ip exe&ution from &urrent test metho#. Syntax for assertFalse assertion is as bello. Assert.assertFalse)&on#ition*, In sort$ assertFalse an# asse rtT rue assertions are opposite to ea&h other. When you ants to assert +True+ value - you &an use assertTrue assertion. An# hen you ants to assert false value - you &an use assertFalse assertion in your selenium eb#river test. et e try to use assertFalse assertion ith simple example. Supposin" e have to &he&!boxs on pa"e one from them is &he&!e# an# another one is not &he&!e#. et e apply assertFalse assertion on both of these &he&! boxes for its &he&!e# status. /epla&e bello "iven example metho#s ith example of  T0IS 1A GE. an# run it ith testn".xml as #es&ribe# on that post.  WebElement &h!2$ &h!3,  45efore6lass  publi& voi# loa#7url)*8  #river."et)+http9::only-testin"-blo".blo"spot.in:3;2<:;3:attributes.html+*,  &h!2 = #river .>n#Element)5 y .xpath)+::input?4name=@option2@+**,  &h!3 = #river .>n#Element)5 y .xpath)+::input ?4name=@option3@+** , B ::Assertion Cetho# - ill Fail  4Test  publi& voi# assertfalse2)* 8  System.out.print)+n+&h!2.isSele&te#)**,  Assert.assertFalse)&h!2.isSele&te#)**,  B  ::Assertion Cetho# - ill 1ass

Upload: sudheer-reddy

Post on 06-Jul-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Example of Assert

8/18/2019 Example of Assert

http://slidepdf.com/reader/full/example-of-assert 1/2

Example Of Assert.assertFalse Assertion In Selenium WebDriver With TestNG

When you are or!in" ith selenium eb#river$ you must be aare about#i%erent !in# of assertions hi&h are available. If you have a enou"h

!nole#"e about eb#river assertions$ 'ou &an &reate very e%e&tive test&ases for your test s&enarios. assertE(uals$ assertNotE(uals an#assertTrue assertions are alrea#yexplaine# in my previous posts. No let e try to un#erstan# assertFalseassertion for selenium eb#river.

Assert.assertFalse)&on#ition* AssertionIt ill &he&! boolean value returne# by &on#ition an# ill pass if returne#value is +False+. If returne# value is pass then this assertion ill fail an# s!ipexe&ution from &urrent test metho#. Syntax for assertFalse assertion is asbello.

Assert.assertFalse)&on#ition*,

In sort$ assertFalse an# assertTrue assertions are opposite to ea&h other.When you ants to assert +True+ value - you &an use assertTrue assertion.An# hen you ants to assert false value - you &an use assertFalse assertionin your selenium eb#river test.

et e try to use assertFalse assertion ith simple example. Supposin" ehave to &he&!boxs on pa"e one from them is &he&!e# an# another one isnot &he&!e#. et e apply assertFalse assertion on both of these &he&! boxesfor its &he&!e# status.

/epla&e bello "iven example metho#s ith example of T0IS 1AGE. an# runit ith testn".xml as #es&ribe# on that post.

  WebElement &h!2$ &h!3, 45efore6lass publi& voi# loa#7url)*8  #river."et)+http9::only-testin"-blo".blo"spot.in:3;2<:;3:attributes.html+*,  &h!2 = #river.>n#Element)5y.xpath)+::input?4name=@option2@+**,  &h!3 = #river.>n#Element)5y.xpath)+::input?4name=@option3@+**,

B::Assertion Cetho# - ill Fail 4Test publi& voi# assertfalse2)* 8  System.out.print)+n+&h!2.isSele&te#)**,  Assert.assertFalse)&h!2.isSele&te#)**, B ::Assertion Cetho# - ill 1ass

Page 2: Example of Assert

8/18/2019 Example of Assert

http://slidepdf.com/reader/full/example-of-assert 2/2

 4Test publi& voi# assertfalse3)* 8  System.out.print)+n+&h!2.isSele&te#)**,  Assert.assertFalse)&h!3.isSele&te#)**, B

In this &ase$ assertfalse2)* metho# ill fail be&ause it is alrea#y &he&!e#so &h!2.isSele&te#)* ill return true value. assertfalse3)* metho# ill passbe&ause 3n# &he&!box is not &he&!e# so it ill return false value. Exe&utionresult ill loo!s li!e bello.