我使用@beforesuite和@aftersuite创建单独的类时遇到Java.lang.NullPointerException错误

如何解决我使用@beforesuite和@aftersuite创建单独的类时遇到Java.lang.NullPointerException错误

我正在使用Cucumber创建脚本并尝试执行功能文件。因此,我创建了一个单独的基础测试类,其中包含@beforesuite和@aftersuite批注和方法,但是当我开始执行此脚本时,出现以下 nullpointerexception 错误。

[RemoteTestNG] detected TestNG version 6.14.3

Scenario: Validate the URL is redirected to "https://www.amazon.in/"                                                                        [90m# Features/amazon_url_validation.feature:3[0m
Logged in successfully
  [32mGiven [0m[32muser is on the landing page of the application[0m                                                                                      [90m# com.amazon.assessment.Testclass.UrlValidateTest.user_is_on_the_landing_page_of_the_application()[0m
  [31mWhen [0m[31mvalidate the URL [0m[31m[1m'http://amzn.in'[0m[31m should be redirected to correct url [0m[31m[1m"https://www.amazon.in/"[0m                                       [90m# com.amazon.assessment.Testclass.UrlValidateTest.validate_the_url_should_be_redirected_to_correct_url(java.lang.String,java.lang.String)[0m
      [31mjava.lang.NullPointerException
    at com.amazon.assessment.Testclass.UrlValidateTest.validate_the_url_should_be_redirected_to_correct_url(UrlValidateTest.java:37)
    at ✽.validate the URL 'http://amzn.in' should be redirected to correct url "https://www.amazon.in/"(file:///C:/Users/Sathish/eclipse-workspace/Edu_Final_Assement/Features/amazon_url_validation.feature:5)
[0m
  [36mThen [0m[36mvalidate the page title [0m[36m[1m'Online Shopping site in India: Shop Online for Mobiles,Books,Watches,Shoes and More - Amazon.in'[0m[36m message[0m [90m# com.amazon.assessment.Testclass.UrlValidateTest.validate_the_page_title_message(java.lang.String)[0m

Scenario: Navigate to create a wishlist,new release pages [90m# Features/amazon_url_validation.feature:8[0m
  [31mWhen [0m[31muser mouse hover on accounts & list page[0m            [90m# com.amazon.assessment.Testclass.UrlValidateTest.user_mouse_hover_on_accounts_list_page()[0m
      [31mjava.lang.NullPointerException
    at com.amazon.assessment.Testclass.UrlValidateTest.user_mouse_hover_on_accounts_list_page(UrlValidateTest.java:57)
    at ✽.user mouse hover on accounts & list page(file:///C:/Users/Sathish/eclipse-workspace/Edu_Final_Assement/Features/amazon_url_validation.feature:9)
[0m
  [36mAnd [0m[36mclick on create a wishlist link[0m                      [90m# com.amazon.assessment.Testclass.UrlValidateTest.click_on_create_a_wishlist_link()[0m
  [36mAnd [0m[36mvalidate navigation is successfull[0m                   [90m# com.amazon.assessment.Testclass.UrlValidateTest.validate_navigation_is_successfull()[0m
  [36mThen [0m[36mclick on New Releases link and vaidate the page[0m     [90m# com.amazon.assessment.Testclass.UrlValidateTest.click_on_new_releases_link_and_vaidate_the_page()[0m

Scenario Outline: Login amazon page and click amazon pay                                                       [90m# Features/amazon_url_validation.feature:25[0m
  [31mWhen [0m[31mUser must be login amazon page using Email as [0m[31m[1m"satishramu@gmail.com"[0m[31m and password as [0m[31m[1m"Priyasatish@1983"[0m [90m# com.amazon.assessment.Testclass.UrlValidateTest.user_must_be_login_amazon_page_using_email_as_and_password_as(java.lang.String,java.lang.String)[0m
      [31mjava.lang.NullPointerException
    at com.amazon.assessment.Testclass.UrlValidateTest.user_must_be_login_amazon_page_using_email_as_and_password_as(UrlValidateTest.java:89)
    at ✽.User must be login amazon page using Email as "xxx@gmail.com" and password as "yyy"(file:///C:/Users/Sathish/eclipse-workspace/Edu_Final_Assement/Features/amazon_url_validation.feature:17)
[0m
  [36mAnd [0m[36mUser must be click amazon pay link[0m                                                                       [90m# com.amazon.assessment.Testclass.UrlValidateTest.user_must_be_click_amazon_pay_link()[0m
  [36mThen [0m[36mValidate the page title should be [0m[36m[1m'Amazon Pay'[0m                                                          [90m# com.amazon.assessment.Testclass.UrlValidateTest.validate_the_page_title_should_be(java.lang.String)[0m

测试跑步者课程:

package com.amazon.assessment.Testclass;

import io.cucumber.testng.AbstractTestNGCucumberTests;

import io.cucumber.testng.CucumberOptions;


//import cucumber.api.CucumberOptions;
//import cucumber.api.testng.AbstractTestNGCucumberTests;



@CucumberOptions(
                  features = "Features",glue = "com.amazon.assessment.Testclass"   

                //,dryRun = true

                //,tags = "@smoke",tags = "not @smoke",plugin = {"pretty","html:target/Cucumber"}

        )


public class TestRunner extends AbstractTestNGCucumberTests {

}

基本测试类:

package amazon_Cucumber.test;

import java.io.IOException;

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


import cucumber.api.Scenario;



public class BaseTest {
    
   static WebDriver driver;
    @BeforeSuite
    
    //public static void launchApplication() throws IOException
    public void setUp(Scenario scenario) throws IOException
    {
        
        //UtilClass.setupBrowser();
        System.setProperty("webdriver.chrome.driver","libs/chromedriver.exe");
        //setDriver( new ChromeDriver());
        driver = new ChromeDriver();
    }
    
    @AfterSuite             
    public void tearDown()
    {
        //      UtilClass.closeBrowser();
        driver.quit();
    }
}

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">
  <test thread-count="5" name="Test">
  <classes>
            <class name="com.amazon.assessment.Testclass.TestRunner"></class>
        </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

功能文件:

Feature: Amazon URL Validation

 Scenario: Validate the URL is redirected to "https://www.amazon.in/"
    Given user is on the landing page of the application
    When validate the URL 'http://amzn.in' should be redirected to correct url "https://www.amazon.in/"
    Then validate the page title 'Online Shopping site in India: Shop Online for Mobiles,Shoes and More - Amazon.in' message

  Scenario: Navigate to create a wishlist,new release pages
   When user mouse hover on accounts & list page
   And  click on create a wishlist link
   And   validate navigation is successfull
   Then  click on New Releases link and vaidate the page
   
   
   Scenario Outline: Login amazon page and click amazon pay
   
   When User must be login amazon page using Email as "<UserName>" and password as "<password>"
   #And  User enter password  as "<password>"
   And User must be click amazon pay link
   Then Validate the page title should be 'Amazon Pay'
  
  Examples: 
  
    |UserName               |password        |
    |xxx@gmail.com|yyy|

步骤定义:

   package com.amazon.assessment.Testclass;


import static org.testng.Assert.assertTrue;

import java.io.IOException;

import org.testng.Assert;

import com.amazon.assessment.Utils.UtilClass;

//import com.amazon.assessment.POM.LandingPage;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

//import cucumber.api.java.en.Given;
//import cucumber.api.java.en.Then;
//import cucumber.api.java.en.When;

public class UrlValidateTest extends BaseTest 
{
    
    
    @Given("user is on the landing page of the application")
    public void user_is_on_the_landing_page_of_the_application() throws IOException 
    {
        //launchApplication();
     System.out.println("Logged in successfully");
    }

    @When("validate the URL {string} should be redirected to correct url {string}")
    public static void validate_the_url_should_be_redirected_to_correct_url(String string,String string2)
    {
       String expectedURL=string2;
       String actualURL=UtilClass.getDriver().getCurrentUrl();
       //String actualURL=util.getDriver().getCurrentUrl();
       System.out.println(actualURL);
       assertTrue(actualURL.equalsIgnoreCase(expectedURL),"URL not found" );
       
    }

    @Then("validate the page title {string} message")
    public static void validate_the_page_title_message(String string)
    {
        String expectedTitle= string;
        System.out.println(expectedTitle);
        String actualTitle=UtilClass.getDriver().getTitle();
        //String actualTitle=util.getDriver().getTitle();
        System.out.println(actualTitle);
        assertTrue(actualTitle.equalsIgnoreCase(expectedTitle),"Page Title not found" );    
    }

任何人都可以帮助我,如何解决此问题。

我的意图是,在运行testng.xml文件之后,光标将指向BaseTest类并打开chrome浏览器,然后光标将指向步骤定义代码并继续该流程。

谢谢

沙爹。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-