执行代码时,测试失败了,因为它将实际标题作为webdriver
它是通过使用iedriver制作的 对基本网址和当前网址进行比较。
package newproject;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverLogLevel;
import org.openqa.selenium.ie.InternetExplorerDriverService;
public class Test1 {
`public static void main(String[] args`) {
// declaration and instantiation of objects/variables
String exePath = "D:\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe";
InternetExplorerDriverService.Builder serviceBuilder = new
InternetExplorerDriverService.Builder();
serviceBuilder.usingAnyFreePort(); // This specifies that sever can pick any available free port to start
serviceBuilder.usingDriverExecutable(new File(exePath));
//Tell it where you server exe is
serviceBuilder.withLogLevel(InternetExplorerDriverLogLevel.TRACE);//Specifies the log level of the server
serviceBuilder.withLogFile(new File("D:\\abc\\Documents\\logFile.txt")); //Specify the log file. Change it based on your system
InternetExplorerDriverService service = serviceBuilder.build();
//Create a driver service and pass it to Internet explorer driver instance
InternetExplorerDriver driver = new InternetExplorerDriver(service);
String baseUrl = "http://www.google.com";
StringBuffer expectedTitle = new StringBuffer("web driver");
String actualTitle = "";
driver.get("http://www.google.com");// get the actual value of the title
actualTitle = driver.getTitle();
System.out.println(actualTitle);
/*compare the actual title of the page with the expected one and prin the result as "Passed" or "Failed"*/
if (actualTitle.equalsIgnoreCase(baseUrl) )
{
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
// exit the program explicitly
System.exit(0);
}
如何获取页面网址而不是WebDriver?
答案 0 :(得分:1)
我刚刚验证了您的代码。它将实际标题视为" Google "不是 webdriver 。
此行不正确:
var timeData=[];
var currentData=[];
var mergedJsonData={};
var yourJsonDataLenght= JSON.yourJsonData.length;
for (infoIndex = 0; infoIndex < yourJsonDataLenght; infoIndex++) {
timeData.push(JSON.yourJsonData.time[infoIndex]);
currentData.push(JSON.yourJsonData.time[infoIndex].power.current);
}
mergedJsonData.push(timeData);
mergedJsonData.push(currentData);
您不应该将标题与基本网址进行比较。比较应该在预期的标题和实际标题之间。