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

Script for an email address that is already registered in the database

on Tue Apr 23, 2013 6:46 pm
Hi,

I write a script for a "Sing Up" page. I have some difficulties at some point.
I need to verify if the email is already registered in the DB. If the email is registered, the script to insert other email.

I attached the script file to this post. Also there are comments where I have to improve the script to add another email in case that a email is already registered in the DB.

Thanks!

Here is the script:
Code:
/* I want to register to a website using the register(Sign Up) page.
If the  email is already registered, I want to build a selenium script which will enter a different email which is not registered in the database. */
package com.example.tests;

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

public class DgennTest extends SeleneseTestCase  {
   private Selenium selenium;

   @Before
   public void setUp() throws Exception {
      selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://website_to_test/");
      selenium.setSpeed("2000");// to run the script slow
      selenium.start();
      selenium.windowMaximize(); // maximize window
      selenium.windowFocus();//focus on window
   }

   @Test
   public void CreateAccount() throws Exception {
      selenium.open("/test_site/");
      selenium.click("link=Sign Up");
      selenium.waitForPageToLoad("30000");
      selenium.type("name=firstname", "My_FirstName");
      selenium.type("name=lastname", "My_LastName");
      // Verify email field and check if the email is already registered into database
            if(selenium.isElementPresent("xpath=//input[@name='email']")){
                  selenium.type("xpath=//input[@name='email']", "test_email@yahoo.com");// here if the email is already registered in the database, I want to to type other email
            }else{
               selenium.type("xpath=//input[@name='email']", "other_email@yahoo.com"); /* the email which I want to be entered if the above email is already in the database. How can I complete this scenario?
                                                                                           I use an if-else statement but is not working*/
            }
      selenium.type("name=password", "test123");
      selenium.type("name=confirm", "test123");
      selenium.click("name=register1");
      selenium.waitForPageToLoad("30000");
      assertTrue(selenium.isTextPresent("The provided email address is already registered"));// this is the message that appears on the page when the email is in the database
      System.out.println("The email is already registered in the DB");
   }

   @After
   public void tearDown() throws Exception {
      selenium.stop();
   }
}
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

Re: Script for an email address that is already registered in the database

on Wed Apr 24, 2013 4:50 pm
I did not quite get if you are facing any issue.
btw you are better off using Selenium WebDriver API as Selenium RC is deprecated

_________________
Thanks
Tarun K
Free Selenium Training
Sumit05
Posts : 4
Join date : 2013-04-29

Re: Script for an email address that is already registered in the database

on Mon Apr 29, 2013 1:42 am
can you tell me, when entering any existing email id, is it giving sudden message or after clicked on submit then its giving error?
Sumit05
Posts : 4
Join date : 2013-04-29

Re: Script for an email address that is already registered in the database

on Mon Apr 29, 2013 1:51 am
selenium.type("xpath","1st mailId");
selenium.click("xpath of submit button"); // if your system check the mail id on clicked submit button.other wise, no need of this command, go directly to "if" condition.

if(selenium.isElementPresent("Xpath of error message")){
selenium.type("xpath",2nd mailId");
}

try this if its working..
I was not implemented this but this was my thinking. let me know if this works. gud luck...
Klau
Posts : 8
Join date : 2012-12-04
Location : Romania

Re: Script for an email address that is already registered in the database

on Tue May 14, 2013 4:29 pm
Sumit05 wrote:selenium.type("xpath","1st mailId");
selenium.click("xpath of submit button"); // if your system check the mail id on clicked submit button.other wise, no need of this command, go directly to "if" condition.

if(selenium.isElementPresent("Xpath of error message")){
selenium.type("xpath",2nd mailId");
}

try this if its working..
I was not implemented this but this was my thinking. let me know if this works. gud luck...

Also, in the same way I thought and it's working.Thanks
But now I want to improve the script: What if the second email is also registered? I use below improved code.
Let say that the script will type this email -> selenium.type("id=email", "test_email@gmail.com");
If this is email already registered an error message will be raised in the page, see below

Code:
// Email verification->Verify if the above email is already registered into database. If this is already in the DB, the script will enter the below email
      if(selenium.isTextPresent("The email is already registered.")){
         String s[] = {"1", "2", "2012"};
         for(int i=0;i<3;i++){
            selenium.click("id=submit_register");
            selenium.waitForPageToLoad("30000");
         selenium.type("id=email", "test_email@gmail.com" +s[i]);
         
      }

When run the script will add this email in the Email field,but in this format: test_email@gmail.com1 or test_email@gmail.com2...

I want to add email in this format: test_email1@gmail.com or test_email2@gmail.com...

What is missed in code?
I try with this selenium.type("id=email", test_email+s[i]@gmail.com); but is not working, the code have errors. How can improve this?
Thank you!
vini546
Active particpant
Active particpant
Posts : 10
Join date : 2012-07-15
Location : Ahmedabad

Re: Script for an email address that is already registered in the database

on Wed Sep 04, 2013 2:02 pm
Code:
if(selenium.isTextPresent("The email is already registered.")){
         String s[] = {"1", "2", "2012"};
         for(int i=0;i<3;i++){
            selenium.click("id=submit_register");
            selenium.waitForPageToLoad("30000");
         selenium.type("id=email", "test_email@gmail.com" +s[i]);
          
      }
Hi Kalu,

     I checked the above code and It's working perfect.But the mistake u did is in terms of "String Concatination"

I mean in this line
 
selenium.type("id=email", "test_email@gmail.com" +s[i]); wrote:
Instead of placing the string value (s[i]) at the end of the line,concatenate it with the string by putting the text string in " " . Please check the below code after modification
Code:
if(selenium.isTextPresent("Email already exists")){
         
           String s[] = {"1", "2", "3","4","5"};
            for(int i=0;i<5;i++){
            selenium.highlight("xpath=//input[@name='txtEmail']");
            Thread.sleep(1500);
            selenium.type("xpath=//input[@name='txtEmail']", "id.email1267@gmail" + s[i] +".com");
            Thread.sleep(1500);
                    
           }
          
       }  

---------------------------------------------------- HAPPY CODING --------------------------------------------------------------
Sponsored content

Re: Script for an email address that is already registered in the database

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