0

Driver class:

package com.deere.gmsr;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Driver {

    public static WebDriver driver;
    public static WebDriver openBrowser(String browserName, String url) throws InterruptedException {

        if(browserName.equals("chrome")) {

            System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
            driver=new ChromeDriver();
            driver.manage().window().maximize();
            driver.get(url);
            driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
            return driver;

        }else
        if(browserName.equals("IE")) {
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
        driver=new ChromeDriver();
        driver.manage().window().maximize();
    //  driver.get(url);
        Thread.sleep(5000); 
        return driver;


    }else
    if(browserName.equals("Firefox")) {
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
        driver=new ChromeDriver();
        driver.manage().window().maximize();
    //  driver.get(url);
        Thread.sleep(5000); 
        return driver;
    }
        return driver;

}


    public static WebDriver getDriver(){
        try{
            if(driver == null) {

            PropertiesFileReader obj=new PropertiesFileReader(); 
            Properties properties=obj.getproperty();
            openBrowser(properties.getProperty("browserName"), properties.getProperty("URL"));
        }
        }catch(Exception e) {
            e.printStackTrace();
        }
        return driver;
    }

    public void quitDriver() {
        driver.close();
        driver.quit();
    }

}

Properties :

package com.deere.gmsr;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesFileReader {

    public Properties getproperty() throws IOException {
        FileInputStream inputstream=null;
        Properties properties=new Properties();
        try {
            properties.load(new FileInputStream("Configuration/config.properties"));
        }catch(Exception e) {
            System.out.println("Exception " +e);
        }

            return properties;
        }


}

Loginpage:

package com.deere.gmsr.page;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;

public class LoginPage {

    //  WebDriver driver;

    public LoginPage(WebDriver driver) {
    //  this.driver=driver;
        PageFactory.initElements(driver, this);

    }

    @FindBy(how=How.ID,using="username")
    public WebElement usernametexbox;

    @FindBy(how=How.ID,using="-password")
    public WebElement passwordtextbox;

    @FindBy(how=How.ID,using="signin-")
    public WebElement signin;

/*  @FindBy(how=How.XPATH,using="//button[@class='btn btn-primary']")
    public WebElement acceptbutton; */

   public void enter_username(String username) {

    usernametexbox.clear();
    usernametexbox.sendKeys(username);
    usernametexbox.getText();
    }

    public void enter_password(String password) {

        passwordtextbox.clear();
        passwordtextbox.sendKeys(password);
    }

    public void clickToSigninbutton() {
        signin.click();
    }

/*  public void clickToAcceptbutton() {


    acceptbutton.click();

    } */

public void fill_LoginDetails() {

    enter_username("ggggg");
    enter_password("hhhhh");



    }


}  

Logintestcase:

package com.deere.gmsr.testcase;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import com.deere.gmsr.Driver;
import com.deere.gmsr.page.LoginPage;

public class LoginTestcase {

    public static WebDriver driver;


    public LoginPage loginpage=new LoginPage(Driver.getDriver());


@Test
public void enter_LoginDetails() {

    loginpage.fill_LoginDetails();

/*   Properties properties=obj.getproperty();
 driver=BrowserUtility.openBrowser(properties.getProperty("browserName"),properties.getProperty("URL")); */

}


@Test
public void click_on_sign_in_button() {

    loginpage.clickToSigninbutton();

    System.out.println("Sign-In successfully");

}

}  

testng xml:

<suite name="GMSR">
    <test name="LoginTest">
        <classes>
            <class name="com.deere.gmsr.testcase.LoginTestcase" />
        </classes>
    </test>
</suite>
6
  • what error message you are getting on webpage? May 1, 2019 at 10:10
  • We found some errors. Please review the form and make corrections.-This is the error message and it doesnt click on sign-in button, but test cases passed ------Sign-In successfully PASSED: click_on_sign_in_button PASSED: enter_LoginDetails =============================================== Default test Tests run: 2, Failures: 0, Skips: 0 ===============================================
    – jay
    May 1, 2019 at 10:15
  • Then it's error of what you are sending the values in your text boxes in username and password, try to enter correct value may be validations required. May 1, 2019 at 10:18
  • thanks, but I have used the same webelements in my cucumber framework but it was working perfect there, even I have added a clear method too which will clear the text
    – jay
    May 1, 2019 at 10:22
  • 1
    It's the error of TestData what you are sending may be in your cucumber framework you was sending correct value. May 1, 2019 at 10:25

1 Answer 1

1

Test case does not fail because it does not include any assertions. As mentioned by @Upkar Singh in the comment - your login test data is not valid, therefore page is showing some kind of error saying that login did not succeed.

If you want the test case to fail, you need to assert that some condition is met (i.e. that some kind of homepage is shown). I do not know how your page looks like but it will be something like this:

Assert.assertTrue(some_condition_met);

The condition can be something like:

driver.getTitle().equals(PAGE_TITLE);

But that is specific to webpage you are testing.

4
  • java.lang.AssertionError: loginpage.clickToSigninbutton() expected [true] but found [false] receiving this message along with at org.testng.Assert.fail(Assert.java:94) at org.testng.Assert.failNotEquals(Assert.java:494) at org.testng.Assert.assertTrue(Assert.java:42) at com.deere.gmsr.testcase.LoginTestcase.click_on_sign_in_button(LoginTestcase.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    – jay
    May 1, 2019 at 13:10
  • All I can say, is that the test case is now failing. Isn't that what you wanted?
    – Moro
    May 1, 2019 at 13:15
  • Right now I have created two test cases in one class, and one method calling to enter uname & pwd and second method calling sign method, I have changed my code limited to one test and now single method calling uname,pwd and signin & it successfully get login to application, but I dont think its a solution
    – jay
    May 1, 2019 at 13:26
  • Can you update your question with the current code and specify what is the problem and what do you want to achieve?
    – Moro
    May 1, 2019 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.