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
你能帮我找到的错误,我看不出有任何显著错误的tracelogs。你能否确认你的实际测试步骤是否被解雇?谢谢 – DebanjanB
请编辑你的问题并格式化你的代码至少 – Matthias
@Matthias,iam new to this,将来会处理这件事,。如果你能帮助我解决这个问题,那么你的帮助真的很值得赞赏。其次,在第二堂课,而不是3000(如果时间[等待])应该是“3”。但仍然面临问题 – VaneetK