Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
Klau
Posts : 8
Join date : 2012-12-04
Location : Romania

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Tue Dec 04, 2012 3:16 pm
Hi,
I created the following script. I use Eclipse and JUnit 4:
Can't add website to the code because: New members are not allowed to post external links or emails for 7 days. Please contact the forum administrator for more information. Please remove this limitation!

Code:
package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class SeleniumJUnit extends SeleneseTestCase {
   @Before
   public void setUp() throws Exception {
      selenium = new DefaultSelenium("localhost", 4444, "*firefox", "website");
      selenium.setSpeed("2000");// to run the script slow
      selenium.start();
   }

   @Test
   public void testAccount() throws Exception {
      selenium.open("/company/login");
      selenium.click("link=Create Account");
      selenium.waitForPageToLoad("30000");
      selenium.type("name=username", "Claudiu");
      selenium.type("name=email", "An email address");
      selenium.type("name=password", "test");
      selenium.type("name=retype_password", "test");
      selenium.type("name=security", "9kk36c");// captcha code
      selenium.click("name=submit_register");
      selenium.waitForPageToLoad("30000");
      selenium.click("name=terms_submit");
      selenium.waitForPageToLoad("30000");
      System.out.println("Sleeping for 9 seconds");
      Thread.sleep(9000); //does not close browser for 9" after the test in executed
   }


   @After
   public void tearDown() throws Exception {
      selenium.stop();
   }
}
The script will try to create an account to a website for example.
I want to to build a new script for Negative Testing (enter wrong data in the fields, a wrong email format etc).
I know what is Negative Testing but I used most in Manual Testing.
Now I want to learn Negative Testing on Automated Testing. I am beginner with Automated Testing.
So, my first question is: How to modify the attached code to make Negative Testing on that page?
Second question: for Negative Testing is more OK to make a new script or can be added to Positive Testing script( to the same code)?
In Eclipse -> JUnit Test Validation bar(Pass or Fail) should be red when make negative testing or green?
Can you modify for me the above code to make Negative Testing to understand exactly how it's works?

I wait for an response,
Thank you very much!
Claudiu


Last edited by Klau on Fri Feb 22, 2013 4:25 pm; edited 6 times in total (Reason for editing : Try to add source code)
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Re: Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Wed Dec 05, 2012 5:11 pm
Let me try to answer but before that, if you beginning with Selenium then use Selenium 2 and not Selenium RC. You could begin here - http://seleniumhq.org/docs/03_webdriver.html

Coming to your question -

Negative testing is automation is going to be same as how you do it manually.
For ex - if you enter different password and confirm password the system should throw error message and your test can assert this error message. Hence in this case it is all about passing invalid data to test and validating that system throws error and handles such use cases. My suggestion is going to be to add different test methods for different use cases. You can reuse most part of code if you followed page object pattern -

http://code.google.com/p/selenium/wiki/PageObjects

Coming to the JUnit test validation bar, it should be green for all test whether negative or positive. A red bar means test fail and a failed negative test means that system does not handle negative use case.

Hope this helps.
avatar
Klau
Posts : 8
Join date : 2012-12-04
Location : Romania

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Re: Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Wed Dec 12, 2012 5:27 pm
tarun3kumar wrote:Let me try to answer but before that, if you beginning with Selenium then use Selenium 2 and not Selenium RC. You could begin here - http://seleniumhq.org/docs/03_webdriver.html

Coming to your question -

Negative testing is automation is going to be same as how you do it manually.
For ex - if you enter different password and confirm password the system should throw error message and your test can assert this error message. Hence in this case it is all about passing invalid data to test and validating that system throws error and handles such use cases. My suggestion is going to be to add different test methods for different use cases. You can reuse most part of code if you followed page object pattern -

http://code.google.com/p/selenium/wiki/PageObjects

Coming to the JUnit test validation bar, it should be green for all test whether negative or positive. A red bar means test fail and a failed negative test means that system does not handle negative use case.

Hope this helps.

Hi,

I build a new tests to a local site by example, to show how Negative Testing is working:

Below is Positive Testing code-> create the account to a website

//Script to create an account for the site
Code:
package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class CreateAccount extends SeleneseTestCase {
   @Before
   public void setUp() throws Exception {
      selenium = new DefaultSelenium("localhost", 4444, "*firefox", "website to test");
      selenium.setSpeed("2000");// to run the script slow
      selenium.start();
      System.out.println("SetUp is running");//
   }

   @Test
   public void testCreateAccount() throws Exception {
      System.out.println("test CreateAccount is running");//
      selenium.open("/ss/");
      selenium.click("css=a.jqTransformSelectOpen");
      selenium.click("link=Register");
      selenium.waitForPageToLoad("30000");
      selenium.type("name=name", "Claudiu Barbulescu");
      selenium.type("name=email", "Your Email");
      selenium.type("name=security_code", "super");
      selenium.click("name=new_user");
      selenium.waitForPageToLoad("30000");
      selenium.type("name=password", "test123");
      selenium.type("name=retype_password", "test123");
      selenium.click("name=new_user");
      selenium.waitForPageToLoad("30000");
      Thread.sleep(6000);
   }

   
   @After
   public void tearDown() throws Exception {
      System.out.println("TearDown is running");//
      selenium.stop();
   }
}


And here is Negative Testing for the above code when try to create an account:

// Negative Testing for Register page
Code:
package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class NegativeTesting extends SeleneseTestCase {
   @Before
   public void setUp() throws Exception {
      selenium = new DefaultSelenium("localhost", 4444, "*chrome", "website to test");
      selenium.setSpeed("2000");
      selenium.start();
   }

   @Test
   public void testRegister() throws Exception {
      selenium.open("/ss/home");
      selenium.click("css=a.jqTransformSelectOpen");
      selenium.click("link=Register");
      selenium.waitForPageToLoad("30000");
//Verify if an account already contain the email
      selenium.type("name=name", "Claudiu");
      selenium.type("name=email", "Your Email");
      selenium.type("name=security_code", "asdfg");
      selenium.click("name=new_user");
      selenium.waitForPageToLoad("30000");
      assertTrue(selenium.isTextPresent("This email address has been already used in the past. You may either want to login using your previous login details, or create another account using another email address"));
//Test wrong captcha
      selenium.type("name=security_code", "asdfg");
      selenium.click("name=new_user");
      selenium.waitForPageToLoad("30000");
      assertTrue(selenium.isTextPresent("› The security code you typed isn't correct"));
      Thread.sleep(6000);
   }

   @After
   public void tearDown() throws Exception {
      selenium.stop();
   }
}


I use assertTextPresent command to assert warning messages from the site. It correct to use this command?If not give me another example.
Thank you!


Last edited by Klau on Fri Feb 22, 2013 4:24 pm; edited 2 times in total
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Re: Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Sun Dec 16, 2012 1:59 am
Seems ok, but in positive use case you did not assert any thing.
avatar
karthik karne
Posts : 2
Join date : 2013-01-29
Age : 33

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Re: Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Fri Feb 01, 2013 1:40 pm
Hi,
I think writing a script where it gets its input values from a file(txt,html,json or xml) will be better. In that give your different sets of inputs. Write exceptional handling for your script and write exception to a file or use selenium.captureScreenshot() to take screen shots.
Thank you,
Karthik Karne
Sponsored content

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse Empty Re: Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

Back to top
Permissions in this forum:
You cannot reply to topics in this forum