• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Negative Testing with Selenium JUnit 4 Remote Control and Eclipse

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I created the following script. I use Eclipse and JUnit 4:

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, "*chrome", "http://dev.server.com/");
selenium.setSpeed("2000");// to run the script slow
selenium.start();
}

@Test
public void testFoobar() throws Exception {
selenium.open("/company/login");
selenium.click("link=I want to create an 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", "XYZ");
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);
}


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


The script will try to create an Business 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
 
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Claudiu Barbulescu wrote:

The script will try to create an Business 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?



First I want to point out that the existing test method doesn't make any assertions. I consider this bad form. I would complete the test case by verifying that an account was actually created, or at least that a confirmation message is displayed to the user. The negative test would submit invalid data in the form and then, perhaps, verify that an account was not created.

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)?



Yes, you can simply add another test method to the class, something like testWrongData, and fill out the form with invalid data.

In Eclipse -> JUnit Test Validation bar(Pass or Fail) should be red when make negative testing or green?



In any test case, we are testing that our application behaves the way we want it to. Red means the test failed -- the application did NOT behave the way we want. Green means the test passed. In a lot of tests we assume the user is interacting with the application exactly as we expect him to. But a negative test tries to suppose the user makes mistakes, and our application handles those situations gracefully. So we always want to see green, regardless of the condition that's being tested.

Can you modify for me the above code to make Negative Testing to understand exactly how it's works?


No, because I don't know the validation rules. But all you need to do is enter invalid data in the form instead of valid data. A friendly application would then display some message to the user informing them that the entered data is bad, and you can write assertions that those messages exist on the page.
 
Claudiu Barbulescu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are no special validation rules. In general for example the User?Email field: the system will check if a user or email already exists in system(database). If the user/email is already registered a message will appears in the site.
Below I build a new test on another web site. The user try to create an account with username and email that already exists. In this case the system must return a message. The same situation when add invalid data like wrong email format, etc.




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

// Negative Testing for Register page



I use assertTextPresent command to assert warning messages from the site. It correct to use this command?If not, give me another example.
Thanks!
 
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic