0
我想使用Selenium Java/Firefox Eclipse插件自動測試webapp。 我正在嘗試進行付款,然後刪除Cookie,以刪除所有存儲的信息。由於某種原因,這不起作用。Selenium Java〜不按預期刪除cookie
public void validationCards(BufferedWriter out){
outFile = out;
ArrayList<String> methodList = new ArrayList<String>();
methodList.add("validationVisaFrench");
methodList.add("validationMCFrench");
methodList.add("validationDiscoverFrench");
methodList.add("validationDinerClubFrench");
methodList.add("validationJCBFrench");
Method method = null;
for(String testToRun:methodList){
try{
method = this.getClass().getMethod(testToRun);
}catch(NoSuchMethodException e){
System.out.println("This failed horribly");
e.printStackTrace();
}catch(RuntimeException ex){
ex.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
try{
PPSCTests tempObj = this;
this.testDriver.manage().deleteAllCookies();
method.invoke(tempObj);
this.testDriver.manage().deleteAllCookies();
}catch (Exception e) {
System.out.println("Cant invoke method for shits and giggles");
e.printStackTrace();
}
}
}
這是我試圖運行測試的一個樣本:
public void validationMCFrench(){
System.out.println("MC French Stored Card");
this.testDriver.manage().deleteAllCookies();
payment("5555555555554444", "frenchQuery");
testSelenium.waitForPageToLoad("20000");
String source = Jsoup.parse(testDriver.getPageSource()).text();
System.out.println("validationMCFrench: "+source);
successOrFail(source, "validationMCFrench", "Example");
this.testDriver.manage().deleteAllCookies();
}
但它不看起來像任何cookie實際刪除。我有點卡住了。任何幫助將是一個讚賞。
呵呵。 ['deleteAllCookies()'](http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Options.html#deleteAllCookies%28%29)方法僅刪除當前域的Cookie。你確定沒有來自其他域的cookies嗎?儘管您在本地運行它們,但這些安全的東西往往會將自己的MasterCard/Visa Cookie附加到「其」網站。與他們的網站有任何互動嗎?也就是說,您可以每次重新啓動Firefox並創建一個新的配置文件。這很慢,但如果沒有解決方案,它肯定會有所幫助。 –
...在你deleteAllCookies()之後,[getCookies()是什麼](http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver。 Options.html#getCookies%28%29)return? –
這樣,基於網絡的cookie只包含一個令牌,如果該cookie被刪除,該令牌應該被刪除。但那並沒有發生。我嘗試了getCookies(),減少了Cookie的數量,但沒有任何改變。 – 1000Suns