我正在做一個硒webdriver,我有一個枚舉爲我測試我的應用程序的環境和應用程序本身的枚舉。我的問題是我無法弄清楚如何在應用程序枚舉中使用環境枚舉來打開它。我在我認爲是我的問題的兩個地方發表了評論。我在第一條評論中發現錯誤,因此無論如何將會有所幫助。你如何使用枚舉與另一個枚舉?
public enum ENV
{
QA, STAGE,
PROD, DEV;
public String toString()
{
switch(this)
{
case QA: return "http://****/qa_was8.html";
case STAGE: return "http://****/stage.html";
case PROD: return "http://****/prod.html";
case DEV: return "http://****/index.html";
default: return "http://****/qa_was8.html";
}
}
}
public enum Application
{
ACCOUNTINVENTORY , AUDITACTIONITEMS;
public static Application chooseApp(String args)
{
File file = new File("H:\\InternStuff\\Selenium\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
for(Application app : Application.values())
{
switch(app)
{
case ACCOUNTINVENTORY:
driver.get(ENV.valueOf(args[1]));//What would go here
driver.findElement(By.linkText("Account Inventory")).click();
driver.findElement(By.name("j_username")).sendKeys("****");
driver.findElement(By.name("j_password")).sendKeys("****");
driver.findElement(By.cssSelector("input[type='submit']")).click();
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
driver.findElement(By.className("inputText")).sendKeys("smith");
driver.findElement(By.className("commandExButton")).click();
break;
case AUDITACTIONITEMS:
driver.findElement(By.linkText("AuditAction Items")).click();
driver.findElement(By.name("j_username")).sendKeys("****");
driver.findElement(By.name("j_password")).sendKeys("****");
driver.findElement(By.cssSelector("input[type='submit']")).click();
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
driver.findElement(By.className("commandExButton")).click();
default:
System.out.println("...");
}
}
return null;
}
}
public static void main(String[] args)
{
if(args.length != 0)
{
Application app = Application.chooseApp(args[1]);
ENV env = ENV.valueOf(args[0]);
if(app != null)
{
app.toString();
}
else if(env != null)
{
env.toString();// Or maybe is my problem here?
}
}
}
}
你能發佈的錯誤? – dkatzel
我在代碼中的第一條評論中有args [1]下面有一條紅線,它表示「表達式的類型必須是數組類型,但它解析爲String」。 – John
您是否有意將chooseApp的參數設置爲String []參數? – wckd