0

I am trying to validate whether user is able to logon or not by verifying whether text is present or not on Home page after logon action. But after login action, execution is not reading assertion code for whether text is present or not on Home page. However, overall test execution run successfully but during execution it skip Assertion. Please help me to identified anything I missed here.

Here is my code:

package com.provider;

import java.io.File;
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;



public class ProApp extends OneClass {

    Workbook wb;
    Sheet sh1;
    int numrow;
    String uname;
    String password1;

    @Test
    public void oneTimeSetUp() throws InterruptedException {


    driver.manage().window().maximize();
    driver.get("xyz.com");
    Thread.sleep(1000);
    driver.findElement(By.xpath("//*[@id='app']/div/main/section/ul/li[1]/a")).click();
    Thread.sleep(1000);

    }


    @Test(dataProvider="testdata")
    public void testFireFox(String uname,String password1) throws InterruptedException

    {

    driver.findElement(By.xpath("//input[@name='username']")).clear();
    Thread.sleep(1000);
    driver.findElement(By.xpath("//input[@name='username']")).sendKeys(uname);
    Thread.sleep(1000);
    driver.findElement(By.xpath("//input[@name='password']")).clear();
    Thread.sleep(1000);
    driver.findElement(By.xpath("//input[@name='password']")).sendKeys(password1);
    Thread.sleep(1000);
    driver.findElement(By.xpath("//button[@name='loginButton']")).click();
    Thread.sleep(1000);

    }


    @Test
    public void loginVerify() {

        Assert.assertEquals("Wel Come to Testing World!", driver.findElement(By.xpath("//*[@id='app']/div/header/nav[1]/div/div/span/span")).getText());

    }   

    @Test
    public void logonActionVerify() {   
    WebElement DashboardHeader = driver.findElement(By.xpath("//*    [@id='app']/div/header/nav[1]/div/div/span/span"));
    DashboardHeader.getText().equals("Wel Come to Testing World!");




    @DataProvider(name="testdata")
    public Object[][] TestDataFeed(){

    try {

    // load workbook
    wb=Workbook.getWorkbook(new File("C://File//Book2.xls"));

    // load sheet in my case I am referring to first sheet only
    sh1= wb.getSheet(0);

    // get number of rows so that we can run loop based on this
    numrow=  sh1.getRows();
    }
    catch (Exception e)

    {
    e.printStackTrace();
    }

    // Create 2 D array and pass row and columns
    Object [][] logindata=new Object[numrow][sh1.getColumns()];

    // This will run a loop and each iteration  it will fetch new row
    for(int i=0;i<numrow;i++){

    // Fetch first row username
        logindata[i][0]=sh1.getCell(0,i).getContents();
    // Fetch first row password
        logindata[i][1]=sh1.getCell(1,i).getContents();

    }

    // Return 2d array object so that test script can use the same
    return logindata;
    }

    } 
2
  • If you change your assertion to Assert.fail() does everything still pass? Commented Feb 19, 2016 at 16:48
  • I used Assert.fail() as below: @Test public void loginVerify() { driver.findElement(By.xpath("//*[@id='app']/div/header/nav[1]/div/div/span/spa‌​n")).getText(); Assert.fail("Wel Come to Testing World!"); Let me know you and I are on same page. However, test is still failing. Error message shown as: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='app']/div/header/nav[1]/div/div/span/span"} Commented Feb 19, 2016 at 17:14

1 Answer 1

2

Please specify the priority for each @Test method to execute in specified order.

 @Test( priority = 1 )
 public void testA1() {
  System.out.println("testA1");
 }

 @Test( priority = 2 )
 public void testA2() {
  System.out.println("testA2");
}

i am expecting loginVerify is executing prior to those setup and login as testng mostly call methods by alphabetical order.

Please post result or exception totally to understand better if above answer does not works.

Thank You, Murali G

Sign up to request clarification or add additional context in comments.

3 Comments

how can I specify priority for @Test(dataProvider="testdata") ? I tried specifying priority like this: @Test(dataProvider="testdata") (priority=2) however error is showing in code. "Multiple markers at this line - Syntax error on token ")", [ expected - Syntax error, insert "]" to complete ArrayAccess - Syntax error, insert ")" to complete Modifiers" I tried all suggestion as mentioned here but error is not going away.
try like this @Test(dataProvider="getData", priority=1) thank you
I updated specifying @test priority as per your suggestion and I kept my old code as mentioned in my initial question and this time execution executed Assertion test. Thanks! Murali.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.