Jump to content

Please help, JUNIT


Recommended Posts

hello guys, I am trying to automate my tests using the JUnit library in Java, Though I keep getting errors that my methods are wrong.

notice that in the main program everything runs perfectly, so I think I might have done something wrong setting up the JUnit tests.

After I clicked on the error line in the console, I am referred to the method in it's page, but nothing seems out of the ordinary.

 

the code:

public class Tests {

    static WebDriver driver;
    static HomePage homePage;
    static RegisterTransferPage registerTransferPage;
    static FormPage formPage;

    @BeforeClass
    public static void initialize() {
        System.setProperty ("webdriver.chrome.driver", "D:\\Desktop\\Selenium\\chromedriver.exe");
        driver = new ChromeDriver ();
        homePage = new HomePage (driver);
        registerTransferPage = new RegisterTransferPage (driver);
        formPage = new FormPage (driver);
    }


    @Test
    public void signInButtonTesting() {
        homePage.signInClick ();
        assertEquals (Constants.SIGNINPAGETEXT, "Please enter your username and password.");
    }

    @Test
    public void goToRegisterTesting() {
        registerTransferPage.clickToRegister ();
        assertEquals (Constants.REGISTERPAGETEXT, "User Information");
    }

    @Test
    public void formFillingTest() {
        formPage.fillTheForm ();
        //formPage.submitAccount();
        assertEquals (Constants.MAINPAGETITLE, "JPetStore Demo");
    }

    @Test
    public void externalLinkRefference() {
        homePage.externalLinkClick ();
        assertEquals (Constants.MYBATISTITLE, "The MyBatis Blog");
    }


    @AfterClass
    public static void closeDriver() {
        driver.close ();
    }
}

 

this is my HomePage

public class HomePage {
    WebDriver driver;

    public HomePage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements (driver, this);
    }

    @FindBy(xpath = "//div[@id='MenuContent']/a[2]")
    WebElement signInButton;

    @FindBy(xpath = "//*[@id='PoweredBy']/a")
    WebElement externalLink;


    public void signInClick() {
        signInButton.click ();
        System.out.println ("Sign in button Checked");
    }

    public void externalLinkClick() {
        externalLink.click ();
        System.out.println ("Link Checked");
    }
}

 

and the error stack

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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
	at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
	at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
	at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
	at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
	at jdk.proxy2/jdk.proxy2.$Proxy11.click(Unknown Source)
	at Pages.HomePage.signInClick(HomePage.java:27)
	at Tests.signInButtonTesting(Tests.java:35)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)


Process finished with exit code -1

if you see anything please let me know

thank you all :)

Edited by EdenIlan93
gave more information
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...