0

I have two classes in my xml file, but I'm unable to execute the fetch class when i run it as test suite. I dont have any errors in my program. I can run the code but only login gets executed. Your help is appreciated!!

Xml file as follows:

<?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="fc.Fetch"/>
      <class name="fc.Login"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Main class

package fc;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.BeforeSuite;

public class MainClass {

    public static WebDriver driver = null;

    @BeforeSuite
    public void driver() {
        if (driver == null) {
            System.setProperty("webdriver.chrome.driver", ".//chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("disable-infobars");
            options.addArguments("start-maximized");
            options.addArguments("--disable-notifications");
            driver = new ChromeDriver(options);
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.get("https://staging-virtual.appspot.com");
        }
    }
}

login class code

package fc;

import org.openqa.selenium.By;
import org.testng.annotations.Test;@Test
public class Login extends MainClass {
    By email = By.xpath("//input[@id='email']");
    By password = By.xpath("//input[@id='pwd']");
    By showpassword = By.xpath("//span[@class='show-pwd']");
    By hidepassword = By.xpath("//span[@class='show-pwd']");
    By signin = By.xpath("//button[@id='login-btn']");
    By gsearch = By.xpath("//a[@class='icon google']");

    generateData random = new generateData();

    @Test(priority = 1)
    public void loginWithBlanks() {

        driver.findElement(email).clear();
        driver.findElement(password).clear();
        driver.findElement(signin).click();
    }

    @Test(priority = 2)
    public void loginWithOnlyPw() {
        driver.findElement(email).clear();
        driver.findElement(password).clear();
        driver.findElement(password).sendKeys(random.generateRandomNames());
        driver.findElement(signin).click();
    }

    @Test(priority = 3)
    public void loginWithOnlyUn() {
        driver.findElement(email).clear();
        driver.findElement(email).sendKeys(random.generateRandomEmail());
        driver.findElement(password).clear();
        driver.findElement(signin).click();
    }

    @Test(priority = 4)
    public void loginGmailId() {
        driver.findElement(email).clear();
        driver.findElement(email).sendKeys(random.generateRandomGmailId());
        driver.findElement(password).clear();
        driver.findElement(password).sendKeys(random.generateRandomAlphanumeric());
        driver.findElement(signin).click();
    }

    @Test(priority = 5)
    public void showAndHidePasswordClick() {
        driver.findElement(password).click();
        driver.findElement(password).clear();
        driver.findElement(password).sendKeys(random.generateRandomNames());
        driver.findElement(showpassword).click();
        driver.findElement(hidepassword).click();
    }

    @Test(priority = 6)
    public void loginFullId() {
        driver.findElement(email).clear();
        driver.findElement(email).sendKeys("******");
        driver.findElement(password).clear();
        driver.findElement(password).sendKeys("*********");
        driver.findElement(signin).click();
    }

    @Test(priority = 7)
    public void oneStepLogin() {
        driver.findElement(email).clear();
        driver.findElement(email).sendKeys("@#$%^&*");
        driver.findElement(password).clear();
        driver.findElement(password).sendKeys("@#$%^&*()");
        driver.findElement(signin).click();
    }

}

fetch class code

package fc;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

@Test
public class Fetch extends Login {

    public Fetch(WebDriver driver) {
        this.driver = driver;
    }
    WebDriverWait wait = new WebDriverWait(MainClass.driver, 10);

    By fetch = By.xpath("//div[@class='fetch btn_cst hint--left']");
    By accountNumber = By.xpath("//input[@id='accountNumber']");
    By load = By.xpath("//a[@class='btn_cst']");
    By fetchClose = By.xpath("//span[@class='popupfetchClose']");
    By popup = By.xpath("//a[@class='cancel']");

    generateData randomData = new generateData();

    @Test(priority = 1)
    public void fetchButtonClick() {
        try {
            driver.findElement(fetch).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(fetch));
            driver.findElement(fetch).click();
        }
    }

    @Test(priority = 2)
    public void fetchAlphabets() {
        driver.findElement(accountNumber).sendKeys(randomData.generateRandomNames());
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {

            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
    }

    @Test(priority = 3)
    public void fetchSplCharacters() {
        driver.findElement(accountNumber).clear();
        driver.findElement(accountNumber).sendKeys("!@#$%^&*(");
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
    }

    @Test(priority = 4)
    public void fetchBlankspace() {
        driver.findElement(accountNumber).clear();
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
    }

    @Test(priority = 5)
    public void fetchOtherLanguage() {
        driver.findElement(accountNumber).clear();
        driver.findElement(accountNumber).sendKeys("స్వాగత ");
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
    }

    @Test(priority = 6)
    public void fetchWithSplCharacters() {
        driver.findElement(accountNumber).clear();
        driver.findElement(accountNumber).sendKeys("^&0082509_-#$");
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
        closePopUp();
    }

    @Test(priority = 7)
    public void fetchSearch() {
        driver.findElement(fetch).click();
        driver.findElement(accountNumber).click();
        driver.findElement(accountNumber).clear();
        driver.findElement(accountNumber).sendKeys("95082509");
        try {
            driver.findElement(load).click();
        }
        catch(Exception e) {
            wait.until(ExpectedConditions.visibilityOfElementLocated(load)).click();
        }
        closePopUp();
    }

    @Test(priority = 8)
    public void fetchClose() {
        fetchButtonClick();
        driver.findElement(fetchClose).click();
    }

    @Test(priority = 9)
    public void closePopUp() {
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(popup)).click();
        }
        catch(Exception e) {
            fetchClose();
        }
    }
}

I have added all the codes for your perusal

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66

1 Answers1

0

Below is code Just created the testNG class file . FirstTestNGFile and another StackoverflowExamle both the classes gets executed.

FirstTestNGFile Class

    public class FirstTestNGFile {


      @Test
      public void f() {

      System.out.println("Test executed");


  }
}

StackoverflowExample

public class StackoverflowExamle {
  @Test
  public void f() {
      System.out.println("Test example");
  }
  @BeforeSuite
  public void beforeSuite() {

      System.out.println("beforeSuite example");
  }

xml file

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
  <test name="Test">
    <classes>
      <class name="firsttestngpackage.StackoverflowExamle"/>
      <class name = "firsttestngpackage.FirstTestNGFile"></class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

output

[TestNGContentHandler] [WARN] It is strongly recommended to add "<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >" at the top of your file, otherwise TestNG may fail or not work as expected.
beforeSuite example
Test example
Test executed

===============================================
Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
prat22
  • 378
  • 1
  • 3
  • 18