Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebForm.getScriptableObject() throws ClassCastException #6

Open
genidoxnick opened this issue Jul 26, 2019 · 2 comments
Open

WebForm.getScriptableObject() throws ClassCastException #6

genidoxnick opened this issue Jul 26, 2019 · 2 comments
Assignees
Milestone

Comments

@genidoxnick
Copy link

Using http-unit 1.7.3, I am trying to set a hidden field parameter. As calling WebForm.setParameter() throws an exception on hidden field, I am calling WebForm.getScriptableObject().setParameterValue() which was working in version 1.6.2.

After upgrading, this no longer works because of the exception.

I also tried WebForm.newScriptable().set() but it does nothing (traced in code and ends up not calling any other methods).

Need help to solve this problem.

Thanks in advance!

@WolfgangFahl WolfgangFahl self-assigned this Jul 28, 2019
@WolfgangFahl
Copy link
Collaborator

WolfgangFahl commented Jul 28, 2019

Thanks for reporting this. Could you please supply a unit test showing the difference in expected and actual behavior. E.g. FormSubmitTest.testFormProperties might be an example where getScriptableObject() is being used.

@WolfgangFahl WolfgangFahl added this to the 1.7.4 milestone Jul 28, 2019
@genidoxnick
Copy link
Author

Hi Wolfgang,

Up to version 1.6.2 the following code would work:

@test
public void testException() throws Exception
{
HttpUnitOptions.setScriptingEnabled(false);

  WebConversation wc = new WebConversation();
  WebRequest request = new GetMethodWebRequest("http://www.google.com");
  WebResponse wr = wc.getResponse(request);

// wr.getForms()[0].setParameter("source", "not important");
wr.getForms()[0].getScriptableObject().setParameterValue("source", "not important");
}

The line in comment is the code that works for all form parameters except for hidden parameters. For hidden parameters, WebForm.setParameter() throws an exception, so you have to resort to going through the getScriptableObject() but it seems there is a bug in 1.7.3 that throws a ClassCastException when calling the getScriptableObject() when Javascript is turned off.

I understand that calling getScriptableObject() is weird when javascript support is turned off but it worked up to version 1.6.2 and again since WebForm.setParameter() throws an exception on hidden fields, there does not seem to be any other options.

Sadly, turning on javascript is not an option as we get very unstable behavior (forms that get be fetched by name but not by ID, buttons that disappear, javascript errors). Turning off javascript has always made it much simpler to test the actual logic.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants