TestBase which contains the intialization method which is creating problem :
(TestBase包含正在创建问题的初始化方法:)
package TestBase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class testBasesetup {
public static Properties prop;
public static WebDriver driver;
public static testBasesetup testBaseObj;
public static EventFiringWebDriver e_driver;
public testBasesetup() throws Exception
{
try {
prop = new Properties();
File src = new File("C:\Users\LENOVO\eclipse-workspace\Demon\src\main\java\Config\config.properties");
FileInputStream ip = new FileInputStream(src) ;
prop.load(ip);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void initialization() throws Exception
{
String browsername = prop.getProperty("browser");
if(browsername.equals("chrome"))
{
System.setProperty("webdriver.chrome.driver", "F:\Eclipse\chromedriver.exe");
WebDriver driver = new ChromeDriver();
}
else if(browsername.equals("firefox"))
{
System.setProperty("webdriver.gecko.driver", "F:\Eclipse\browser\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
String URLtoTest = prop.getProperty("URL");
Thread.sleep(1000);
}
}
Test Class which I am running and this is creating issue.
(我正在运行的测试类,这正在产生问题。)
I guess there is some issue with driver variable but don't know the error: (我猜驱动程序变量存在一些问题,但不知道错误:)
package PageTest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Pages.LoginPage;
import TestBase.testBasesetup;
public class LoginPageTest extends testBasesetup{
LoginPage LoginPageObj;
testBasesetup testBaseObj;
public LoginPageTest() throws Exception
{
super();
}
@BeforeMethod
public void setup() throws Exception
{
initialization();
LoginPageObj = new LoginPage();
Thread.sleep(2000);
}
@Test()
public void LoginCheck() throws Exception
{
LoginPageObj.login("[email protected]","Potatok");
}
@AfterMethod
public void tearDown()
{
driver.quit();
}
}
Image of error:
(错误图片:)
Code
(码)
ask by Ishmeet Singh translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…