Java 无法修复webdriver的问题
下面是包含驱动程序脚本的代码,当它运行时,它给出了以下问题。当它显示打开浏览器时,它抛出异常,看起来不相关。我尝试检查xalan.jar,但在这方面似乎没有问题Java 无法修复webdriver的问题,java,selenium-webdriver,Java,Selenium Webdriver,下面是包含驱动程序脚本的代码,当它运行时,它给出了以下问题。当它显示打开浏览器时,它抛出异常,看起来不相关。我尝试检查xalan.jar,但在这方面似乎没有问题 package com.totsy.test; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method;
package com.totsy.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.totsy.xls.read.Xls_Reader;
public class DriverScript {
public static Logger APP_LOGS;
//suite.xlsx
public Xls_Reader suiteXLS;
public int currentSuiteID;
public String currentTestSuite;
// current test suite
public static Xls_Reader currentTestSuiteXLS;
public static int currentTestCaseID;
public static String currentTestCaseName;
public static int currentTestStepID;
public static String currentKeyword;
public static int currentTestDataSetID=2;
public static Method method[];
public static Method capturescreenShot_method;
public static Keywords keywords;
public static String keyword_execution_result;
public static ArrayList<String> resultSet;
public static String data;
public static String object;
// properties
public static Properties CONFIG;
public static Properties OR;
public DriverScript() throws NoSuchMethodException, SecurityException{
keywords = new Keywords();
method = keywords.getClass().getMethods();
capturescreenShot_method =keywords.getClass().getMethod("captureScreenshot",String.class,String.class);
}
public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, NoSuchMethodException, SecurityException {
FileInputStream fs = new FileInputStream("src/test/java/com/totsy/config/config.properties");
CONFIG= new Properties();
CONFIG.load(fs);
fs = new FileInputStream("src/test/java/com/totsy/config/or.properties");
OR= new Properties();
OR.load(fs);
//System.out.println(CONFIG.getProperty("testsiteURL"));
//System.out.println(OR.getProperty("name"));
DriverScript test = new DriverScript();
test.start();
}
public void start() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException{
// initialize the app logs
APP_LOGS = Logger.getLogger("devpinoyLogger");
APP_LOGS.debug("Hello");
APP_LOGS.debug("Properties loaded. Starting testing");
// 1) check the runmode of test Suite
// 2) Runmode of the test case in test suite
// 3) Execute keywords of the test case serially
// 4) Execute Keywords as many times as
// number of data sets - set to Y
APP_LOGS.debug("Intialize Suite xlsx");
suiteXLS = new Xls_Reader("src/test/java/com/totsy/xls/Suite.xlsx");
for(currentSuiteID=2;currentSuiteID<=suiteXLS.getRowCount(Constants.TEST_SUITE_SHEET);currentSuiteID++){
APP_LOGS.debug(suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.Test_Suite_ID, currentSuiteID)+" -- "+ suiteXLS.getCellData("Test Suite", "Runmode", currentSuiteID));
// test suite name = test suite xls file having tes cases
currentTestSuite=suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.Test_Suite_ID, currentSuiteID);
if(suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.RUNMODE, currentSuiteID).equals(Constants.RUNMODE_YES)){
// execute the test cases in the suite
APP_LOGS.debug("******Executing the Suite******"+suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.Test_Suite_ID, currentSuiteID));
currentTestSuiteXLS=new Xls_Reader("src/test/java/com/totsy/xls/"+currentTestSuite+".xlsx");
// iterate through all the test cases in the suite
for(currentTestCaseID=2;currentTestCaseID<=currentTestSuiteXLS.getRowCount("Test Cases");currentTestCaseID++){
APP_LOGS.debug(currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.TCID, currentTestCaseID)+" -- "+currentTestSuiteXLS.getCellData("Test Cases", "Runmode", currentTestCaseID));
currentTestCaseName=currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.TCID, currentTestCaseID);
if(currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.RUNMODE, currentTestCaseID).equals(Constants.RUNMODE_YES)){
APP_LOGS.debug("Executing the test case -> "+currentTestCaseName);
if(currentTestSuiteXLS.isSheetExist(currentTestCaseName)){
// RUN as many times as number of test data sets with runmode Y
for(currentTestDataSetID=2;currentTestDataSetID<=currentTestSuiteXLS.getRowCount(currentTestCaseName);currentTestDataSetID++)
{
resultSet = new ArrayList<String>();
APP_LOGS.debug("Iteration number "+(currentTestDataSetID-1));
// checking the runmode for the current data set
if(currentTestSuiteXLS.getCellData(currentTestCaseName, Constants.RUNMODE, currentTestDataSetID).equals(Constants.RUNMODE_YES)){
// iterating through all keywords
executeKeywords(); // multiple sets of data
}
createXLSReport();
}
}else{
// iterating through all keywords
resultSet= new ArrayList<String>();
executeKeywords();// no data with the test
createXLSReport();
}
}
}
}
}
}
public void executeKeywords() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
// iterating through all keywords
for(currentTestStepID=2;currentTestStepID<=currentTestSuiteXLS.getRowCount(Constants.TEST_STEPS_SHEET);currentTestStepID++){
// checking TCID
if(currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.TCID, currentTestStepID))){
data=currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.DATA,currentTestStepID );
if(data.startsWith(Constants.DATA_START_COL)){
// read actual data value from the corresponding column
data=currentTestSuiteXLS.getCellData(currentTestCaseName, data.split(Constants.DATA_SPLIT)[1] ,currentTestDataSetID );
}else if(data.startsWith(Constants.CONFIG)){
//read actual data value from config.properties
data=CONFIG.getProperty(data.split(Constants.DATA_SPLIT)[1]);
}else{
//by default read actual data value from or.properties
data=OR.getProperty(data);
}
object=currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.OBJECT,currentTestStepID );
currentKeyword=currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.KEYWORD, currentTestStepID);
APP_LOGS.debug(currentKeyword);
// code to execute the keywords as well
// reflection API
for(int i=0;i<method.length;i++){
if(method[i].getName().equals(currentKeyword)){
keyword_execution_result=(String)method[i].invoke(keywords,object,data);
APP_LOGS.debug(keyword_execution_result);
resultSet.add(keyword_execution_result);
// capture screenshot
capturescreenShot_method.invoke(keywords,
currentTestSuite+"_"+currentTestCaseName+"_TS"+currentTestStepID+"_"+(currentTestDataSetID-1),
keyword_execution_result);
//how do we call
// what will be the file name
}
}
}
}
}
public void createXLSReport(){
String colName=Constants.RESULT +(currentTestDataSetID-1);
boolean isColExist=false;
for(int c=0;c<currentTestSuiteXLS.getColumnCount(Constants.TEST_STEPS_SHEET);c++){
if(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET,c , 1).equals(colName)){
isColExist=true;
break;
}
}
if(!isColExist)
currentTestSuiteXLS.addColumn(Constants.TEST_STEPS_SHEET, colName);
int index=0;
for(int i=2;i<=currentTestSuiteXLS.getRowCount(Constants.TEST_STEPS_SHEET);i++){
if(currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.TCID, i))){
if(resultSet.size()==0)
currentTestSuiteXLS.setCellData(Constants.TEST_STEPS_SHEET, colName, i, Constants.KEYWORD_SKIP);
else
currentTestSuiteXLS.setCellData(Constants.TEST_STEPS_SHEET, colName, i, resultSet.get(index));
index++;
}
}
if(resultSet.size()==0){
// skip
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, Constants.KEYWORD_SKIP);
return;
}else{
for(int i=0;i<resultSet.size();i++){
if(!resultSet.get(i).equals(Constants.KEYWORD_PASS)){
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, resultSet.get(i));
return;
}
}
}
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, Constants.KEYWORD_PASS);
// if(!currentTestSuiteXLS.getCellData(currentTestCaseName, "Runmode",currentTestDataSetID).equals("Y")){}
}
}
package com.totsy.test;
导入java.io.FileInputStream;
导入java.io.IOException;
导入java.lang.reflect.InvocationTargetException;
导入java.lang.reflect.Method;
导入java.util.ArrayList;
导入java.util.Properties;
导入org.apache.log4j.Logger;
导入com.totsy.xls.read.xls\u读卡器;
公共类驱动程序脚本{
公共静态记录器应用程序日志;
//suite.xlsx
公共Xls_阅读器套件;
公共信息系统;
公共字符串currentTestSuite;
//当前测试套件
公共静态Xls_读取器currentTestSuiteXLS;
公共静态int currentTestCaseID;
公共静态字符串currentTestCaseName;
公共静态int currentTestStepID;
公共静态字符串;关键字;
公共静态int currentTestDataSetID=2;
公共静态法[];
公共静态方法捕获截图法;
公共静态关键词;
公共静态字符串关键字\u执行\u结果;
公共静态ArrayList结果集;
公共静态字符串数据;
公共静态字符串对象;
//性质
公共静态属性配置;
公共静态属性或;
public DriverScript()抛出NoSuchMethodException、SecurityException{
关键词=新关键词();
方法=关键字.getClass().getMethods();
capturescreenShot_method=keywords.getClass().getMethod(“capturescreenShot”,String.class,String.class);
}
公共静态void main(字符串[]args)抛出IllegalAccessException、IllegalArgumentException、InvocationTargetException、IOException、NoSuchMethodException、SecurityException{
FileInputStream fs=newfileinputstream(“src/test/java/com/totsy/config/config.properties”);
CONFIG=新属性();
CONFIG.load(fs);
fs=newfileinputstream(“src/test/java/com/totsy/config/or.properties”);
或=新属性();
或。加载(fs);
//System.out.println(CONFIG.getProperty(“testsiteURL”);
//System.out.println(或.getProperty(“名称”));
DriverScript测试=新建DriverScript();
test.start();
}
public void start()引发IllegalAccessException、IllegalArgumentException、InvocationTargetException、NoSuchMethodException、SecurityException{
//初始化应用程序日志
APP_LOGS=Logger.getLogger(“devpinoyLogger”);
APP_LOGS.debug(“Hello”);
APP_LOGS.debug(“加载属性。开始测试”);
//1)检查测试套件的运行模式
//2)测试套件中测试用例的运行模式
//3)连续执行测试用例的关键字
//4)尽可能多地执行关键字
//数据集数-设置为Y
APP_LOGS.debug(“初始化套件xlsx”);
suiteXLS=新的Xls_阅读器(“src/test/java/com/totsy/Xls/Suite.xlsx”);
对于(currentSuiteID=2;currentSuiteID感谢Thomas改进了它。请检查包含net.sf.saxon.Configuration
的库的确切版本,以及该版本中的类是否提供了方法newConfiguration()
。如果您的类路径上有一个版本未提供该方法,则会导致此类错误。请注意,您的类路径上可能有多个包含该类的LIB,这取决于类加载器加载类的顺序(并且您不希望手动更改)-因此,请查找同一lib的多个版本或具有相同类的不同lib。另请参见:
2016-03-01 20:39:37 DEBUG devpinoyLogger:70 - Hello
2016-03-01 20:39:37 DEBUG devpinoyLogger:71 - Properties loaded. Starting testing
2016-03-01 20:39:37 DEBUG devpinoyLogger:77 - Intialize Suite xlsx
2016-03-01 20:39:39 DEBUG devpinoyLogger:83 - Check out -- Y
2016-03-01 20:39:39 DEBUG devpinoyLogger:88 - ******Executing the Suite******Check out
2016-03-01 20:39:40 DEBUG devpinoyLogger:92 - ShoppingCart -- Y
2016-03-01 20:39:40 DEBUG devpinoyLogger:96 - Executing the test case -> ShoppingCart
2016-03-01 20:39:40 DEBUG devpinoyLogger:102 - Iteration number 1
2016-03-01 20:39:40 DEBUG devpinoyLogger:144 - openBrowser
2016-03-01 20:39:40 DEBUG devpinoyLogger:40 - Opening browser
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.totsy.test.DriverScript.executeKeywords(DriverScript.java:151)
at com.totsy.test.DriverScript.start(DriverScript.java:107)
at com.totsy.test.DriverScript.main(DriverScript.java:63)
Caused by: java.lang.NoSuchMethodError: net.sf.saxon.Configuration.newConfiguration()Lnet/sf/saxon/Configuration;
at net.sf.saxon.xpath.XPathFactoryImpl.<init>(XPathFactoryImpl.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.xml.xpath.XPathFactoryFinder.loadFromService(Unknown Source)
at javax.xml.xpath.XPathFactoryFinder._newFactory(Unknown Source)
at javax.xml.xpath.XPathFactoryFinder.newFactory(Unknown Source)
at javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
at javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:99)
at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:60)
at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:425)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:403)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:89)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at com.totsy.test.Keywords.openBrowser(Keywords.java:42)
... 7 more