Results 1 to 3 of 3
  1. #1
    Crazy1234 is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default Control from Driver class to another and back

    Hi All - I'm new to this forum. I'm working on Selenium Webdriver and have general Java question. Looking for some guidance.
    My test package in Java has multiple independent classes (Test 1,2,3 ..etc). I have a driver class (outside of that package) that should execute Test 1, then get the result to a variable in driver class, then to Test 2 & back to driver and so on. On driver class after executing each test class, I want to record whether it's successful or not. Please suggest different ways it cab be done.
    I thought about constructors, but that wouldnt return anything back from classes. I can call methods of individual classes, but that makes my driverclass look ugly when I develop rest of the classes that could be close to 50+. Also, the selection of which class (Test 1 / 2/ 3) to be run would depend on an input from user (for now, I just have Temp1, Temp2 strings, down the line I will replace them with an input from user (spreadsheet or something) that tells which class file to be run.
    Here is my driver class:

    Java Code:
    	public class Driver {
    
    	 public static String Temp1 = "Test1";
    	 public static String Temp2 = "Test2";
    	
    	 @BeforeSuite
    	 public void initialize() {
    	 	System.out.println("Before Suite ");
    	 }
    	
    	 @Test
    	 public void callerSripts() {
    		System.out.println("Calling");
    		new Test1();
    		}
    	
    	}
    
    	
    
    	package Tests;
    	import org.testng.annotations.BeforeClass;
    	import org.testng.annotations.Test;
    	import Base.Driver;
    
    	public class Test1{
    	
     	 @BeforeClass
    	 public void print() {
    	 	System.out.println("Befire test 1 ");
    	 }
    	
    	 @Test
    	 public Test1() {
    	 	System.out.println("Inside called 1");
    	 }
    	}
    
    	package Tests;
    
    	import org.testng.annotations.BeforeClass;
    	import org.testng.annotations.BeforeSuite;
    	import org.testng.annotations.Test;
    	import Base.Driver;
    
    	public class Test2{
    	
    	 @BeforeClass
     	 public void print() {
    		System.out.println("Before Test2 ");
    	 }
    	
    	 @Test
    	 public void here() {
    		System.out.println("Inside called 2");
    	 }
    
    	}
    Last edited by Crazy1234; 08-26-2013 at 06:22 PM. Reason: For maintaining standards

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Control from Driver class to another and back

    Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Control from Driver class to another and back

    Also go through Code Conventions for the Java Programming Language: Contents

    Method names should start with a lowercase letter.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Back to the math class....
    By Lionlev in forum Advanced Java
    Replies: 11
    Last Post: 10-31-2012, 08:19 PM
  2. Replies: 0
    Last Post: 03-03-2012, 01:01 AM
  3. Replies: 6
    Last Post: 02-08-2012, 06:42 PM
  4. Replies: 3
    Last Post: 11-24-2011, 01:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •