E ai cavalera… é exatamente isso que eu precisava… só que como não conheço muito bem… tenho algumas dúvidas… vê se vc sabe me ajudar…
quando tento acessar um site normal px: http://www.google.com.br
eu não consigo conexão…
eu acho q tenho que configurar o proxy … eu configurei assim e não deu certo
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost","111.111.1.1");
System.getProperties().put("proxyPort", "1111");
vc sabe o nome da propriedade de “senha” e “usuario” ? pq acho que tenho que informar isso tbm!!! quando uso o firefox na minha máquina informo o usuario e senha tbm…
o outro ponto que ta foda de dar certo… é conseguir acessar o outro form a tela depois do login … veja meu codigo
try {
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost","111.111.1.1");
System.getProperties().put("proxyPort", "1111");
WebConversation wc = new WebConversation();
WebResponse response = wc.getResponse("http://localhost:8080/BIG/tools/formLogin.html");
WebForm form = response.getFormWithID("formLogin");
form.setParameter("formLogin:login", "wt");
form.setParameter("formLogin:password", "123");
WebRequest request = form.getRequest("formLogin:sendButton");
response = wc.getResponse(request);
String html = response.getText();
System.out.println(html);
} catch (Exception e) {
e.printStackTrace();
System.out.println();
}
neste código estou setando o usuario e login…
ele está conseguindo recuperar o form blz…
consegue setar o “formLogin:login” tbm… pq depois no html que retorna … o value=“wt” desse input… vem setado corretamente…
o problema é que o campo senha… é criptografado no meu bean
tentei passar o valor ja criptografado :
form.setParameter("formLogin:password", "202cb962ac59075b964b07152d234b70");
e ele me retorna o mesmo html da pagina de login
quando passo sem criptografar:
form.setParameter("formLogin:password", "123");
ele da um erro muito grande cara… vou tentar resumir … colocando o começo e o fim do erro…
começo
com.meterware.httpunit.ScriptException: Script 'var Prototype={Version:'1.6.0',Browser:{IE:!!(window.attachEvent&&!window.opera),Opera:!!window.opera,WebKit:navigator.userAgent.indexOf('AppleWebKit/')>-1,Gecko:navigator.userAgent.indexOf('Gecko')>-1&&navigator.userAgent.indexOf('KHTML')==-1,MobileSafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/)},BrowserFeatures:{XPath:!!document.evaluate,ElementExtensions:!!window.HTMLElement,SpecificElementExtensions:document.createElement('div').__proto__&&document.createElement('div').__proto__!==document.createElement('form').__proto__},ScriptFragment:'<script[^>]*>([\\S\\s]*?)<\/script>',JSONFilter:/^\/\*-secure-([\s\S]*)\*\/\s*$/,emptyFunction:function(){},K:function(x){return x}};if(Prototype.Browser.MobileSafari)
Prototype.BrowserFeatures.SpecificElementExtensions=false;if(Prototype.Browser.WebKit)
Prototype.BrowserFeatures.XPath=false;var Class={create:function(){var parent=null,properties=$A(arguments);if(Object.isFunction(properties[0]))
parent=properties.shift();function klass(){this.initialize.apply(this,arguments);}
Object.extend(klass,Class.Methods);klass.superclass=parent;klass.subclasses=[];if(parent){var subclass=function(){};subclass.prototype=parent.prototype;klass.prototype=new subclass;parent.subclasses.push(klass);}
for(var i=0;i<properties.length;i++)
klass.addMethods(properties[i]);if(!klass.prototype.initialize)
klass.prototype.initialize=Prototype.emptyFunction;klass.prototype.constructor=klass;return klass;}};Class.Methods={addMethods:function(source){var ancestor=this.superclass&&this.superclass.prototype;var properties=Object.keys(source);if(!Object.keys({toString:true}).length)
properties.push("toString","valueOf");for(var i=0,length=properties.length;i<length;i++){var property=properties[i],value=source[property];if(ancestor&&Object.isFunction(value)&&value.argumentNames().first()=="$super"){var method=value,value=Object.extend((function(m){return function(){return ancestor[m].apply(this,arguments)};})(property).wrap(method),{valueOf:function(){return method},toString:function(){return method.toString()}});}
this.prototype[property]=value;}
return this;}};var Abstract={};Object.extend=function(destination,source){for(var property in source)
destination[property]=source[property];return destination;};Object.extend(Object,{inspect:function(object){try{if(object===undefined)return'undefined';if(object===null)return'null';return object.inspect?object.inspect():object.toString();}catch(e){if(e instanceof RangeError)return'...';throw e;}},toJSON:function(object){var type=typeof object;switch(type){case'undefined':case'function':case'unknown':return;case'boolean':return object.toString();}
if(object===null)return'null';if(object.toJSON)return object.toJSON();if(Object.isElement(object))return;var results=[];for(var property in object){var value=Object.toJSON(object[property]);if(value!==undefined)
results.push(property.toJSON()+': '+value);}
return'{'+results.join(', ')+'}';},toQueryString:function(object){return $H(object).toQueryString();},toHTML:function(object){return object&&object.toHTML?object.toHTML():String.interpret(object);},keys:function(object){var keys=[];for(var property in object)
keys.push(property);return keys;},values:function(object){var values=[];for(var property in object)
values.push(object[property]);return values;},clone:function(object){return Object.extend({},object);},isElement:function(object){return object&&object.nodeType==1;},isArray:function(object){return object&&object.constructor===Array;},isHash:function(object){return object instanceof Hash;},isFunction:function(object){return typeof object=="function";},isString:function(object){return typeof object=="string";},isNumber:function(object){return typeof object=="number";},isUndefined:function(object){return typeof object=="undefined";}});Object.extend(Function.prototype,{argumentNames:function(){var names=this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");return names.length==1&&!names[0]?[]:names;},bind:function(){if(arguments.length<2&&arguments[0]===undefined)return this;var __method=this,args=$A(arguments),object=args.shift();return function(){return __method.apply(object,args.concat($A(arguments)));}},bindAsEventListener:function(){var __method=this,args=$A(arguments),object=args.shift();return function(event){return __method.apply(object,[event||window.event].concat(args));}},curry:function(){if(!arguments.length)return this;var __method=this,args=$A(arguments);return function(){return __method.apply(this,args.concat($A(arguments)));}},delay:function(){var __method=this,args=$A(arguments),timeout=args.shift()*1000;return window.setTimeout(function(){return __method.apply(__method,args);},timeout);},wrap:function(wrapper){var __method=this;return function(){return wrapper.apply(this,[__method.bind(this)].concat($A(arguments)));}},methodize:function(){if(this._methodized)return this._methodized;var __method=this;return this._methodized=function(){return __method.apply(null,[this].concat($A(arguments)));};}});Function.prototype.defer=Function.prototype.delay.curry(0.01);Date.prototype.toJSON=function(){return'"'+this.getUTCFullYear()+'-'+
(this.getUTCMonth()+1).toPaddedString(2)+'-'+
this.getUTCDate().toPaddedString(2)+'T'+
this.getUTCHours().toPaddedString(2)+':'+
this.getUTCMinutes().toPaddedString(2)+':'+
this.getUTCSeconds().toPaddedString(2)+'Z"';};
fim
delete Event.cache[eventID];}});}' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot find function createElement. (httpunit#12506)
at com.meterware.httpunit.javascript.ScriptingEngineImpl.handleScriptException(ScriptingEngineImpl.java:64)
at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:95)
at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
at com.meterware.httpunit.ParsedHTML.interpretScriptElement(ParsedHTML.java:364)
at com.meterware.httpunit.ParsedHTML$ScriptFactory.recordElement(ParsedHTML.java:533)
at com.meterware.httpunit.ParsedHTML$2.processElement(ParsedHTML.java:744)
at com.meterware.httpunit.NodeUtils$PreOrderTraversal.perform(NodeUtils.java:241)
at com.meterware.httpunit.ParsedHTML.loadElements(ParsedHTML.java:760)
at com.meterware.httpunit.ParsedHTML.getFrames(ParsedHTML.java:1101)
at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:199)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)
at br.com.webtraffic.big.channel.Teste.main(Teste.java:28)
não tenho certeza se isso está certo tbm…
WebRequest request = form.getRequest("formLogin:sendButton");
coloquei o codigo html que o java me retorna la em cima… se quiser dar uma olhada…
se alguem tiver uma luz ai…
vlwwwwwwwwwwwwwwwww