想要从concordion打开浏览器。
试图从System.java类打开浏览器。但观察到WebDriver driver = new FirefoxDriver();
未执行。
这是我项目的结构; -
System.java类: -
package com.tutorialspoint;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class System {
public String initization(String browserName){
String url = null;
if (browserName=="firefox")
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
url = driver.getCurrentUrl();
}
return url;
}
}
这是我的BrowserFixture.java类: -
package specs.tutorialspoint;
@RunWith(ConcordionRunner.class)
public class BrowserFixture {
System system = new System();
public String initization(String browserName){
return system.initization(browserName);
}
}
这是我的.html输入: -
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Browser Initilization</h1>
<div class="example">
<h3>Example</h3>
<table>
<tr>
<th>browserName</th>
<th>initization</th>
</tr>
<tr concordion:execute="#result = initization(#browserName)">
<td concordion:set="#browserName">firefox</td>
</tr>
</table>
</div>
</body>
</html>
答案 0 :(得分:0)
您需要使用string.equals(Object other)
函数来比较字符串,而不是==
运算符。
如果您更换以下内容,浏览器将打开OK:
if (browserName=="firefox")
使用:
if (browserName.equals("firefox"))
有关详细信息,请参阅How do I compare Strings in Java。
有关此示例的一些一般性观察,请参阅我对此问题的评论。