1

I am using selenium with page factory method to automate a login page. An error came when I try to run my code.

My complete code is..

package com.docmgr.Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.WebElement;
public class LoginPage
{
    WebDriver driver;
    public LoginPage(WebDriver driver)
    {
        this.driver=driver;
    }
@FindBy(how=How.NAME,using="username")
@CacheLookup
WebElement username;
@FindBy(how=How.NAME,using="password")
@CacheLookup
WebElement password;
@FindBy(how=How.CLASS_NAME,using="button")
@CacheLookup
WebElement button;
@FindBy(how=How.LINK_TEXT,using="Forgot Password")
@CacheLookup
WebElement fp;
public void login_Doc(String uid,String pas)
{
    username.sendKeys(uid);
    password.sendKeys(pas);
    button.click();
}
}


package com.docmgr.TestCases;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;

import com.docmgr.Pages.LoginPage;

import Helper.BrowserFactory;

public class LoginTest 
{
    @Test
    public void chechValidUser()
    {
        System.setProperty("firefox.webdriver.marionette","pathToGeckodriver");
WebDriver driver=BrowserFactory.startBrowser("firefox","54.68.159.876/docmgr");
LoginPage login=PageFactory.initElements(driver,LoginPage.class);
login.login_Doc("jgsdg","123");

    }
}


package Helper;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class BrowserFactory
{
    static WebDriver driver;
    public static WebDriver startBrowser(String browsName,String url)
    {
        if(browsName.equals("firefox"))
        {
            driver=new FirefoxDriver();
        }

        driver.manage().window().maximize();
        driver.get(url);
        return driver;
    }




}

Error is :

FAILED: chechValidUser org.openqa.selenium.WebDriverException: Target URL 54.68.159.204/docmgr is not well-formed. Command duration or timeout: 27 milliseconds Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700' System info: host: 'naveen-Inspiron-3542', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-45-generic', java.version: '1.8.0_111' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.0, platform=LINUX, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 992a8a4c-efe1-462f-a656-2f8faadf4c06

  • Have you added the jar files properly to your test project? – IAmMilinPatel Nov 10 '16 at 10:10
  • @TESTasy ya sure – user21268 Nov 10 '16 at 10:11
  • @TESTasy Error I mentioned there where I need to put this command System.setProperty("firefox.webdriver.marionette","pathToGeckodriver"); – user21268 Nov 10 '16 at 10:12
  • Usually its right before you initialize your driver. – IAmMilinPatel Nov 10 '16 at 10:22
  • @TESTasy Please tell me the correct path – user21268 Nov 10 '16 at 10:25
1

If I understand this correctly, You should not put "pathToGekoDriver" in your code. There you should mention the path where the gecko driver is installed like:

System.setProperty("firefox.webdriver.marionette", "E:\\Softwares\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
  • Hai, Everyone I got the error. I didn't add the protocol. http://...... and Thank you every one for the contribution – user21268 Nov 11 '16 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy