Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1448
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T16:28:54+00:00 2022-05-30T16:28:54+00:00

FAILED CONFIGURATION: @BeforeMethod setUp – Selenium Java TestNG

  • 0

[ad_1]

I am trying to execute Selenium Java Project with TestNG but I am getting the Configurations Problems related to TestNG annotations. I am using Page object model design pattern. The chromedriver gets executed successfully for each testcase and it lands on login page but after that it crashes and gives error about Failed Configurations @BeforeMethod.

I am sharing the whole code and console errors. Any Solution for this folks! Been stuck here for the long time.

Page Classes.

Base Page:

package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

public class BasePage{

public WebDriver driver;
public WebDriverWait wait;  

public BasePage(WebDriver driver, WebDriverWait wait) {
    
    this.driver = driver;
    this.wait = wait;
}

//Generic Methods

public void click(By elementlocation) {
    driver.findElement(elementlocation).click();
}

public void writeText(By elementlocation, String text) {
    driver.findElement(elementlocation).sendKeys(text);
}

public String readText(By elementlocation) {
    return driver.findElement(elementlocation).getText();
}

public void waitVisibility(By elementlocation) {
    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(elementlocation));
}

public void waitElementToBeClickable(By elementlocation ) {
    wait.until(ExpectedConditions.elementToBeClickable(elementlocation));
}

public void assertEquals (By elementlocation, String expectedText) {
    waitVisibility(elementlocation);
    Assert.assertEquals(readText(elementlocation), expectedText);
}
    
}

Login Page with Methods:

package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginPage extends BasePage{
    
    public LoginPage(WebDriver driver, WebDriverWait wait) {
        super(driver, wait);
    }

    By email = By.xpath("//input[@data-placeholder="Enter your username"]");
    By pwd = By.xpath("//input[@data-placeholder="Enter your Password"]");
    By LoginBtn = By.xpath("//button//span[text()='Login']");
    By emptyLoginVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
    By emptyPasswordVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
    By emptyUserNameVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");

    //methods
    public LoginPage LoginToAMS(String username, String password) {
        
        writeText(email, username);
        
        writeText(pwd, password);
        
        click(LoginBtn);
                
        return this;
    }
    
    public LoginPage EmptyLoginVerification (String expectedText) {
        
        assertEquals(emptyLoginVerification, expectedText);
        
        return this;    
    }
    
    public LoginPage EmptyPasswordVerification (String expectedText) {
        
        assertEquals(emptyPasswordVerification, expectedText);
        
        return this;        
    }
    
    public LoginPage EmptyUserNameVerification (String expectedText) {
        
        assertEquals(emptyUserNameVerification, expectedText);
        
        return this;        
    }
}

Below are the TestClasses Now.

BaseTest:

package tests;

import java.time.Duration;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;


public class BaseTest {
    
    public WebDriver driver;
    public WebDriverWait wait;
    

    @BeforeMethod
    public void setup() {
        
        System.setProperty("WebDriver.chrome.driver", "C:\\eclipse\\eclipse-workspace\\ams\\chromedriver.exe");
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(15));
        driver.manage().window().maximize();
        driver.get("http://dev-ims.dplit.com/");
        
    }
    
    @AfterMethod
    public void teardown() {
        driver.close();
    }
}

And here is the actual TestClass:

package tests;

import static org.testng.Assert.assertEquals;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import Pages.HomePage_ListOfItems;
import Pages.LoginPage;

public class LoginTestCases extends BaseTest{
    
    LoginPage loginpage = new LoginPage(driver, wait);
    
    private String username = "[email protected]";
    private String password = "123456";
    
    @Test(priority=0)
    public void Valid_Login_To_AMS() {
        loginpage.LoginToAMS(username, password);   
    }
    
    @Test(priority=1)
    public void Empty_Login_To_AMS() {
        loginpage.LoginToAMS("","");
        loginpage.EmptyLoginVerification("Both Password and user name are required.");
    }
    
    @Test(priority=2)
    public void UserName_EmptyPassword() {
        loginpage.LoginToAMS(username,"");
        loginpage.EmptyPasswordVerification("Both Password and user name are required.");
    }
    
    @Test(priority=4)
    public void EmptyUserName_PasswordFill( ) {
        loginpage.LoginToAMS("", password);
        loginpage.EmptyUserNameVerification("Both Password and user name are required.");
    }

}

The errors that I am getting are below:

[RemoteTestNG] detected TestNG version 7.4.0
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}) on port 52405
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:45:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:45:44 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}) on port 50748
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:46:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:46:31 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
FAILED CONFIGURATION: @BeforeMethod setup
org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
from disconnected: unable to send message to renderer
  (Session info: chrome=101.0.4951.67)
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'NASIR-S-LTP', ip: '192.168.10.18', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [afb96e2642d9f544c41d7d722caab5d3, get {url=http://dev-ims.dplit.com/}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 101.0.4951.67, chrome: {chromedriverVersion: 101.0.4951.41 (93c720db8323..., userDataDir: C:\Users\nasir.n\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:53544}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:53544/devtoo..., se:cdpVersion: 101.0.4951.67, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: afb96e2642d9f544c41d7d722caab5d3
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:312)
    at tests.BaseTest.setup(BaseTest.java:29)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
    at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.testng.TestRunner.privateRun(TestRunner.java:794)
    at org.testng.TestRunner.run(TestRunner.java:596)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
    at org.testng.SuiteRunner.run(SuiteRunner.java:276)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
    at org.testng.TestNG.runSuites(TestNG.java:1063)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

[ad_2]

  • 0 0 Answers
  • 35 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 5251 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1098 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1047 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.