Multiple classes in TestNG

358 views
Skip to first unread message

sravya pudota

unread,
Aug 4, 2016, 8:24:27 AM8/4/16
to testng...@googlegroups.com
Hi,

Could somebody help on this one.

I'm new to TestNG. I have two classes, one is login and other is Staff Directory user credentials.In each class I have different methods with priorities. I called two classes in testng.xml file. First login has to run  then signup ,one after the other. 

But for me first class is working fine and second it is showing error. When I run separately it is working fine.

My xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="catie.SingleRun.Login"/>
      <class name="catie.SingleRun.StaffDirec"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

My code
Class 1:
package catie.SingleRun;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Login {
static WebDriver driver = new FirefoxDriver();
@Test(priority=1)
public static void login() throws InterruptedException {
System.out.println("maximize");
driver.manage().window().maximize();
Thread.sleep(1000);
System.out.println("navigate");
driver.navigate().to("https://10.10.1.80");
Thread.sleep(1000);
driver.findElement(By.id("username")).sendKeys("status");
driver.findElement(By.id("pwd")).sendKeys("statsoladmin");
driver.findElement(By.xpath("/html/body/form/center/div/table[1]/tbody/tr[4]/td/img")).click();
System.out.println("Login sucessfully");
}
}

Class 2:
package catie.SingleRun;
import org.testng.annotations.Test;
import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
public class StaffDirec{
static WebDriver driver;
@Test(priority=1)
public static void StaffDirApplicationAdmin() throws InterruptedException {
// to locate application administrator frame
//driver.switchTo().frame("mainPage");
// to locate application administrator
driver.findElement(By.xpath("/html/body/table/tbody/tr/td/table/tbody/tr/td[3]/div/a/img")).click();
driver.findElement(By.xpath("html/body/table/tbody/tr/td/table[2]/tbody/tr[6]/td[2]/a")).click();
Thread.sleep(1000);
// driver.switchTo().frame("msgadmin");
Thread.sleep(1000);
System.out.println("Clicked on Video Gallery sucessfully");
}
//Add Menu in Document Repository
@Test(priority=2)
public static void StaffDir() throws InterruptedException {
//Click on Add Staff Department link
driver.findElement(By.linkText("Add Staff Department")).click();
Thread.sleep(1000);
//Click on Add link
driver.findElement(By.linkText("Add")).click();
Thread.sleep(1000);
//Enter Department name
driver.findElement(By.id("category")).sendKeys("Sciences");
Thread.sleep(500);
//Enter Description
driver.findElement(By.id("description")).sendKeys("Medicine & Science");
Thread.sleep(500);
//Upload Images
File file1=new File("resources\\StaffDirectory\\1.jpg");
Thread.sleep(2000);
String path1=file1.getAbsolutePath();
Thread.sleep(2000);
driver.findElement(By.id("icon")).sendKeys(path1);
Thread.sleep(2000);
//Click on Submit button
driver.findElement(By.xpath(".//*[@id='cat_addhref']/input")).click();
Thread.sleep(1000);
//Click on Back link
driver.findElement(By.linkText("Back")).click();
Thread.sleep(1000);
//Click on Add Staff link
driver.findElement(By.linkText("Add Staff")).click();
Thread.sleep(1000);
//Enter Staff Code
driver.findElement(By.id("staffCode")).sendKeys("L123");
Thread.sleep(500);
//Select Department staffDirectoryGroup
WebElement se=driver.findElement(By.id("staffDirectoryGroup"));
Select dropdown = new Select(se);
     dropdown.selectByVisibleText("Sciences");
Thread.sleep(1000);
//Enter Title
driver.findElement(By.id("nameSalutation")).sendKeys("Mr");
Thread.sleep(1000);
//Enter Staff First name
driver.findElement(By.id("staffName")).sendKeys("Staff First");
Thread.sleep(500);
//Enter Staff Last name
driver.findElement(By.id("lastName")).sendKeys("StaffLast");
Thread.sleep(500);
//Enter Staff Contact number
driver.findElement(By.id("contactNo")).sendKeys("6165164");
Thread.sleep(500);
//Enter Staff Mobile number
driver.findElement(By.id("mobNo")).sendKeys("9521211152");
Thread.sleep(500);
//Enter Staff Email id
driver.findElement(By.id("emailAddress")).sendKeys("catie...@gmail.com");
Thread.sleep(500);
//Enter Staff Device Extension
driver.findElement(By.id("sipExtension")).sendKeys("4001");
Thread.sleep(500);
//Enter Staff Security code
driver.findElement(By.id("securityCode")).sendKeys("123456");
Thread.sleep(500);
 
//Upload Staff Image
File file2=new File("resources\\StaffDirectory\\i1.jpg");
Thread.sleep(2000);
String path2=file2.getAbsolutePath();
Thread.sleep(2000);
driver.findElement(By.id("staffImg")).sendKeys(path2);
Thread.sleep(2000);
//Upload Staff Bio
File file3=new File("resources\\StaffDirectory\\i1.pdf");
Thread.sleep(2000);
String path3=file3.getAbsolutePath();
Thread.sleep(2000);
driver.findElement(By.id("pdfFile")).sendKeys(path3);
Thread.sleep(2000);
//Click on Add button
driver.findElement(By.id("addButton")).click();
Thread.sleep(1000);
}
 
}

Thank you,
-Sravya


SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Aug 4, 2016, 7:48:34 PM8/4/16
to testng-users
Hi Sravya,

Can you please let me know what's the error you are getting?. I guess you need to do groupbyInstances=true.
Else, testng will run the tests based on priority.

Let me know if you still face issues.

Subramanyam

driver.findElement(By.id("emailAddress")).sendKeys("catie.s...@gmail.com");

Thank you,
-Sravya


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam
Reply all
Reply to author
Forward
0 new messages