2017-05-16 16 views
0

我已經創建了這兩個文件。
我給了瀏覽器名稱和Url的第一個文件。
第二個文件,我在其中給出了xpath的邏輯名。在執行用java編寫的腳本後面臨錯誤(Selenium WEbdriver)

我已經相應地創建了兩個類。
在第一堂課,我創造了所有的功能。
在第二類中,iam調用了第一類中存在的函數(使用繼承概念[擴展])。

上傳所有文件。
第一個文件:

Browser=Firefox 
AppURL=https://www.myntra.com/ 

第二個文件:

Myntra_Search_Xpath=.//*[@id='desktop-header-cnt']/div/div[3]/input 

一流

package Basepack; 

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

import org.openqa.selenium.By; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class baseclass { 
    public static FirefoxDriver driver; 

    public static String getpropValue(String PName) throws IOException{ 
     Properties prop=new Properties(); 
     FileInputStream pi=new FileInputStream("C:\\Users\\Desktop\\workspace\\SeleFirstClass\\src\\Basepack\\Objprop"); 
     prop.load(pi); 
     String Pvalue=prop.getProperty(PName); 
     return Pvalue; 

    } 

    public static String getpathValue(String Pname) throws IOException{ 
     Properties prop=new Properties(); 
     FileInputStream pi=new FileInputStream("C:\\Users\\Desktop\\workspace\\SeleFirstClass\\src\\Basepack\\Objpath"); 
     prop.load(pi); 
     String Pvalue=prop.getProperty(Pname); 
     return Pvalue; 

    } 
    public static void openBrowser(){ 
     System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\geckodriver.exe"); 
     driver=new FirefoxDriver(); 

    } 
    public static void navigate(String URLName) throws IOException{ 
    String path=getpropValue(URLName); 
    driver.get(path); 
    } 
    public static void closeBrowser(){ 
     driver.close(); 
    } 
    public static void click(String Value) throws IOException{ 
     String path=getpathValue(Value); 
     driver.findElement(By.xpath(path)).click(); 
    } 

    public static void type(String path, String Value) throws IOException{ 
     String Locator=getpathValue(path); 
     driver.findElement(By.xpath(Locator)).sendKeys(Value); 
    } 

public static void wait(int i) throws InterruptedException 
    { 
     Thread.sleep(i*1000); 
    } 
} 

二等

package Basepack; 

import java.io.IOException; 

import org.testng.annotations.AfterMethod; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.Test; 

public class FirstTestNG extends baseclass{ 
    @BeforeMethod 
    public void beforemethod() throws IOException, InterruptedException 
    { 
     openBrowser(); 
     navigate("AppURL"); 
     wait(3000); 

    } 
    @AfterMethod 
    public void aftermethod() 
    { 
     closeBrowser(); 
    } 

    @Test 
    public void invalidlogin1() throws IOException, InterruptedException 
    { 
     wait(3000); 
     type("Flipkart_login_Xpath", "Nike Shoes"); 
    } 

} 

以下是錯誤的描述

1494929368178 geckodriver INFO Listening on 127.0.0.1:8576 
1494929368783 geckodriver::marionette INFO Starting browser \\?\C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"] 
1494929369821 addons.manager ERROR startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70" data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < AddonManagerInternal.validateBlocklist()@resource://gre/modules/AddonManager.jsJavaScmr:i6p6t5 e<r rAodrd:o nrMeasnoaugrecreI:n/t/egrrnea/lm.osdtualretsu/pA(d)[email protected]:./j/sgmr,e /lmionde 1639: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized 
ules/AddonManager.jsm:832 < this.AddonManagerPrivate.startup()@resource://gre/modules/AddonManager.jsm:2773 < amManager.prototype.observe()@resource://gre/components/addonManager.js:57 
1494929371707 Marionette INFO Listening on port 53003 
JavaScript error: undefined, line 492: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getCharPref] 
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2484: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized 
May 16, 2017 3:39:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession`enter code here`INFO: Detected dialect: W3C 
+0

你能幫我找到的錯誤,我看不出有任何顯著錯誤的tracelogs。你能否確認你的實際測試步驟是否被解僱?謝謝 – DebanjanB

+1

請編輯你的問題並格式化你的代碼至少 – Matthias

+0

@Matthias,iam new to this,將來會處理這件事,。如果你能幫助我解決這個問題,那麼你的幫助真的很值得讚賞。其次,在第二堂課,而不是3000(如果時間[等待])應該是「3」。但仍然面臨問題 – VaneetK

回答

0

嘗試添加DesiredCapabilities

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
    capabilities.setCapability("marionette", true); 
    WebDriver driver = new FirefoxDriver(capabilities); 
相關問題