首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Annotaion_testng.Login_case.login(Login_case.java:34 java.lang.NullPointerException

Annotaion_testng.Login_case.login(Login_case.java:34 java.lang.NullPointerException
EN

Stack Overflow用户
提问于 2018-07-24 06:40:21
回答 1查看 61关注 0票数 0
代码语言:javascript
复制
package Annotaion_testng;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class Login_case {

  public String baseUrl = "https://www.eventerprise.com";
  String driverpath = "C://Users//fizan//Documents//testing//webdriver_soft//fire_fox_driver//geckodriver.exe";
  public WebDriver driver;

  @BeforeMethod
  public void f() throws InterruptedException {

    System.out.println("opening firefox");
    System.setProperty("webdriver.gecko.driver", driverpath);
    WebDriver driver = new FirefoxDriver();
    driver.get(baseUrl);
    Thread.sleep(10000);
  }

  @Test
  public void login(){
    System.out.println("click on login link from header");

    //code is failing from here
    driver.findElement(By.xpath(".//*[@id='app']/div/div/div/header/div[1]/div[1]/div[2]/ul/li[4]/a")).click();

    driver.findElement(By.id("email")).sendKeys("fijan@atyantik.com");

    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    //enter  password

    driver.findElement(By.id("password")).sendKeys("atyantik@1234");

    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    //click on login button

    driver.findElement(By.xpath(".//*[@id='eve-modal']/div/div[1]/div/div/div[2]/div/div/div/div[1]/div[2]/form/div[4]/button")).click();

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    //click on log out from header

    System.out.println("logging out");

    driver.findElement(By.xpath(".//*[@id='app']/div/div/header/div[1]/div[1]/div[2]/div[1]/ul/li[7]/a")).click();  
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-24 06:46:04

您正在f WebDriver driver = new FirefoxDriver();中跟踪fWebDriver driver = new FirefoxDriver();,因为您已经正确声明了这个字段,删除了新的重声明。

代码语言:javascript
复制
driver = new FirefoxDriver(); 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51492043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档