Can HTMLUnit enter data in password fields? - java

My HTMLUnit tests are failing, and I've got a feeling it's because I'm entering a password using the setValueAttribute() method and that for some reason doesn't work. Any ideas? Am I supposed to pass HTMLUnit the encrypted form of the password?
EDIT:
The code to set the pass:
loginForm.getInputByName("loginPassword").setValueAttribute("1234");

This should work, can you please submit a test case to HtmlUnit user-list, so we investigate further?
Yours,
Ahmed Ashour
http://asashour.blogspot.com/

The password field is not encrypted. It is just not rendered as plain text in the browser (dots or stars instead). You can make it visible with a tool, such as Webdeveloper toolbar for Firefox. So this should not be the problem. I am using HtmlUnit myself and it works.

It does work, I have it working.
I would check to make sure you getting the correct input field name. If not, can you post the stacktrace.
The below code works for me.
form.getInputByName("password").setValueAttribute("1234");

Related

How to expose Swagger UI without authentication?

I'm trying to make the SwaggerUi interface not ask for authorization every time I boot.
I tried to enter in my Configure class:
.authorizeRequests().antMatchers("/actuator/**","/mypath/**").permitAll()
and
.authorizeRequests().antMatchers("/mypath/**").permitAll()
but without success.
Actuator on the other hand works fine without authorization with this code structure
Thanks everyone for a possible answer!
The basic problem is that even in the Sprinc-doc documentation they put you the case that you entered too. In order to make the code work you have to enter multiple permissions, one for each path. In your case it will have to be something like this:
.authorizeRequests().antMatchers("/actuator/**","/v2/**","/mypath/**","/swagger.yml","/anypath/").permitAll()
Try this:
.authorizeRequests().antMatchers("/swagger-ui/**").permitAll()
Then just go here:
http://localhost:[YOUR PORT]/swagger-ui/
p.s Don't forget the / at the end of the URL :)

Microstrategy URL API

Reading from this link, link, link, link, link and this SO answer about Microstrategy URL API, I want to pass the answer to one or more prompts in the request to that the report document is executed automatically without requiring the user to enter information.
When I tried to use valuePromptAnswer method for multiple prompt, Microstrategy only take the first argument. The other argument doensn't works. Here are the URL
http://111.222.333.444/MicroStrategy/servlet/mstrWeb?Server=******&Project=*****&Port=0&evt=4001&src=mstrWeb.4001&reportID=226F3C76422512B0E56995939C230DF1&visMode=0&reportViewMode=1&valuePromptAnswers=12^11
The microstrategy only takes the first argument.
Using elementsPromptAnswers generate the same result, only the first prompt receive the value
http://111.222.333.444/MicroStrategy/servlet/mstrWeb?Server=****&Project=***&Port=0&evt=4001&src=mstrWeb.4001&reportID=226F3C76422512B0E56995939C230DF1&visMode=0&reportViewMode=1&elementsPromptAnswers=F9365CA24CFDFD394F3D01ACB4EA5F21:1;474209F94C5C6140979F31848D01E40F:2
Using objectPromptAnswer generate the same result
http://111.222.333.444/MicroStrategy/servlet/mstrWeb?Server=****&Project=****&Port=0&evt=4001&src=mstrWeb.4001&reportID=226F3C76422512B0E56995939C230DF1&visMode=0&reportViewMode=1&objectsPromptAnswers=474209F94C5C6140979F31848D01E40F~12~DistChl
I've read the documentation carefully for each step by step. What I'm missed out? Is there any configuration on server side to accept all argument / parameters?
Thanks in advance.
We had did the thing you talk about using the next url:
mstrWeb?port=0&evt=2048001&src=mstrWeb.2048001&documentID=YOURDOCUMENTID&valuePromptAnswers={&Prompt1&}^{&Prompt2&}^{&Prompt3&}^{&Prompt4&}^{&Prompt5&}^{&Prompt6&}&promptAnswerMode=2
In the previous example, {&Prompt1&}, {&Prompt2&}, etc. are responses of a previous prompt. In your case, the url to create should be the next url:
mstrWeb?port=0&evt=2048001&src=mstrWeb.2048001&documentID=226F3C76422512B0E56995939C230DF1&valuePromptAnswers=12^11&promptAnswerMode=2
I think that your problem could be on the evt or promptAnswerMode parameters, because if these are not correctly configured it can get in troubles.
Hope that this answer solves your problem.
Greetings.

element.sendKeys(password) method in Selenium sending too many keys

I'm writing Selenium tests for an application my company's working on. It's Selenium 3, and I'm using the 32-bit Internet Explorer Driver(IEDriverServer.exe) because I was using the 64-bit version but it was very slow to do anything.
I'm trying to populate a password field (with id="password"), and I'm using the following line of code:
driver.findElement(By.id("password")).sendKeys("welcome123");
where driver is an InternetExplorerDriver. What's happening instead of inputting the 10 characters "welcome123", is this:
The image of the populated password field
Please let me know what I can do to stop this from happening. I don't know what keys are being sent, but I am sure that in my code it says just "welcome123" and not something obvious like "welcome123_________".
Thanks!
Using the lines
driver.findElement(By.id("password")).click(); and
driver.findElement(By.id("password")).clear(); and then following it up with the
sendKeys("welcome123");
method call, the field is populated correctly. The problem was because IE was auto populating the password field based on password saving settings, and it was just tacking "welcome123" on the to the end.

What to post in HTTP POST

I am working on an android app which helps the user login. The site which I want to login is this
I have been now searching for 2 days straight but haven't found myself any answer as to what all I should post.
The problem that I am facing is what all parameters should I post ? I have tried every possible combination of hidden and non-hidden and also tried with cookies.
It would be really kind of you if you could give me the list of the parameters that I should include in my request.
As of now , this is my code
Document docl = Jsoup.connect("http://erp.mitpune.com/AdminLogin.aspx")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("txtPassword","*******")
.data("__LASTFOCUS","")
.data("__EVENTTARGET","")
.data("__EVENTARGUMENT","")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("__VIEWSTATEGENERATOR","B8B84CAE")
.data("hdnMsg","")
.data("txtUserId","********")
.data("btnLogin","Login")
.method(Connection.Method.POST).post();
I am using jsoup,on android studio, but just the list would help me a lot.
Thanks in advance
txtUserId and txtPassword
posted to Adminlogin.aspx
inside form1
so form1.txtUserId and form1.txtPassword
This is a quick output of data variables by Fiddler Chrome Extension
ScriptManager1: UpdatePanel1|btnLogin
__ASYNCPOST: true
__EVENTARGUMENT:
__EVENTTARGET: btnLogin
__LASTFOCUS:
__VIEWSTATE: /wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD
__VIEWSTATEGENERATOR: B8B84CAE
hdnMsg:
txtPassword: sasasa
txtUserId: jajas
Seems like _ASYNCPOST and ScriptManager1 are not in your post variables .

How to execute random Javascript code on a web page?

I'm using htmlunit to test some pages and I'd like to know how can I execute some javascript code in the context of the current page. I'm aware that the docs say I'd better emulate the behavior of a user on a page, but it isn't working this way :( (I have a div which has an onclick property, I call its click method but nothing happens). So I've made some googling and tried:
JavaScriptEngine jse = webClient.getJavaScriptEngine();
jse.execute(page, what here?);
Seems like I have to instantiate the script first, but I've found no info on how to do it (right). Could someone share a code snippet showing how to make webclient instance execute the needed code?
You need to call executeJavaScript() on the page, not on webClient.
Example:
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
webClient.setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage("http://www.google.com/ncr");
ScriptResult scriptResult = page.executeJavaScript("document.title");
System.out.println(scriptResult.getJavaScriptResult());
prints "Google". (I'm sure you'll have some more exciting code to put in there.)
I don't know the JavaScriptEngine you're quoting and maybe it's not the answer you want, but this sounds like a perfect case for Selenium IDE.
Selenium IDE is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.
In TestPlan using the HTMLUnit backend the google example is:
GotoURL http://www.google.com/ncr
set %Title% as evalJavaScript document.title
Notice %Title%

Categories

Resources