gpt4 book ai didi

java - 断言不起作用基于 Excel 的数据驱动测试 selenium Web 驱动程序 java

转载 作者:行者123 更新时间:2023-12-02 03:55:27 24 4
gpt4 key购买 nike

我试图通过验证登录操作后主页上是否存在文本来验证用户是否能够登录。但是在登录操作之后,执行不会读取主页上是否存在文本的断言代码。然而,整体测试执行成功运行,但在执行过程中它跳过断言。请帮助我找出我在这里遗漏的任何内容。

这是我的代码:

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;
}

}

最佳答案

请指定每个@Test方法的优先级以指定顺序执行。

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

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

我期望 loginVerify 在这些设置和登录之前执行,因为 testng 主要按字母顺序调用方法。

如果上述答案不起作用,请完整发布结果或异常,以便更好地理解。

谢谢你,穆拉利G

关于java - 断言不起作用基于 Excel 的数据驱动测试 selenium Web 驱动程序 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com