简体   繁体   English

从 maven-Selenium 测试中获取 Initializer 异常

[英]Getting Exception In Initializer error from maven- Selenium test

i am getting an Exception In Initializer error in my code and don't know what i am doing wrong, please help.i am happy to answer if you have any questions: Below is the error i am getting from maven: [ERROR] Failures.我的代码中出现初始化程序异常错误,我不知道我做错了什么,请帮忙。如果您有任何问题,我很乐意回答:以下是我从 maven 收到的错误:[ERROR] 失败. [ERROR] Homepage_Test:startURL.13->BaseClass:globalDriver.26 » ExceptionInInitializer. [错误] Homepage_Test:startURL.13->BaseClass:globalDriver.26 » ExceptionInInitializer。

//My Homepage_Test which includes all tests. startURL() invokes webdriver and runs to get website:

public class Homepage_Test extends BaseClass{
@BeforeTest
public void startURL() {
globalDriver();
}
@Test
public void search_product() {
Homepage_Methods.search_and_add();
}
@Test
public void verify_product_text() {
Homepage_Methods.verify_search();
}
@Test
public void scroll_down_page() {
Homepage_Methods.scroll_down_verify_text();
}
@AfterClass
public void clear_field() {
Homepage_Methods.clear_inputfield();
}
}

// My BaseClass: // 我的基类:

public class BaseClass {
public static void globalDriver() {
System.setProperty("webdriver.gecko.driver" , System.getProperty("user.dir")+"/resources/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
@SuppressWarnings("unused")
Shop_Page_Objects cpo = new Shop_Page_Objects(driver);
@SuppressWarnings("unused")
Homepage_Objects hpom = new Homepage_Objects(driver);
@SuppressWarnings("unused")
Shop_Page_Methods spm = new Shop_Page_Methods(driver);
@SuppressWarnings("unused")
Homepage_Methods hpm = new Homepage_Methods(driver);
DesiredCapabilities dc = new DesiredCapabilities();
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
dc.setCapability(FirefoxOptions.FIREFOX_OPTIONS,options);
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.get("blabla website");
}
}


//Line 26 of BaseClass contains Shop_Page_Methods which is very long but here is the snippet:

public class Shop_Page_Methods extends BaseClass{
private static WebDriver driver;
public Shop_Page_Methods(WebDriver driver) {
Shop_Page_Methods.driver = driver ;
}
public static WebElement product_1_to_add_to_cart = Shop_Page_Objects.get_cart_product_1();
public static List<WebElement> all_products = Shop_Page_Objects.get_All_Products();
public static int products_count = Shop_Page_Objects.get_All_Products().size();
public static List<WebElement> all_price = Shop_Page_Objects.get_price();
public static String remove_number = Shop_Page_Objects.get_number_to_remove().getText();
public static String[] remover_1 = remove_number.split("");
public static int remove_number_1 = Integer.parseInt(remover_1[0]);

i figured out the issue was that i was doing the following before actually clicking/switching to their container: public static String remove_number = Shop_Page_Objects.get_number_to_remove().getText();我发现问题是我在实际单击/切换到他们的容器之前做了以下操作: public static String remove_number = Shop_Page_Objects.get_number_to_remove().getText(); public static String[] remover_1 = remove_number.split("");公共 static String[] remover_1 = remove_number.split(""); public static int remove_number_1 = Integer.parseInt(remover_1[0]);公共 static int remove_number_1 = Integer.parseInt(remover_1[0]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM