How to fill all forms within a page with htmlunit - htmlunit

Is it possible to fill all forms of a page with random data (and then click on all buttons) using htmlunit test? Does anyone know an example?

It is possible to do that:
HTMLPage page = /* Your Page */
List<HTMLForm> forms = page.getForms();
for(HTMLForm form : forms) {
List<HTMLElement> elms = form.getHtmlElementsByTagNames(Arrays.asList("input", "textarea"/*etc*/));
List<HTMLSubmitInput> submits = new List<HTMLSubmitInput>();
for(HTMLElement elm : elms) {
if(elm instanceof HTMLSubmitInput) {
submits.add((HTMLSubmitInput) elm);
} else if (elm instanceof HtmlTextInput || elm instanceof HtmlPasswordInput) {
((HTMLInput) elm).setValue("BLA"/* add your random text here */)
} // Add more input types if you want
}
for(HTMLSubmitInput submit: submits) {
submit.click(); /*Capture the page here*/
}
}
For more of those input types, you can check out the HtmlInput JavaDocs.

Related

Determine the list of IR filter's functions/operators in Oracle APEX 19.1

Is there a way to hide some Functions/Operators in the Row Filter of APEX 19.1's Interactive Report? Some end-users get confused with as many functions/operators that they do not used.
Thanks for any considerations.
While APEX doesn't support this out of the box, it is doable with JavaScript. Every time the filter dialog is displayed, content is brought from the server to the client and injected into the DOM. You just need to modify the content before the user can see it. One way to achieve this is by using the MutationObserver interface: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
Here are some steps you could follow to do it (tested in APEX 19.2):
Go to the Interactive Report and set the Static ID to my-irr.
Go to the page level attributes and add the following code to the Function and Global Variable Declaration field:
function removeIRFilterOperators() {
var irRegId = 'my-irr';
var filterOperatorsToRemove = ['!=', 'ABS'];
var observer;
function detectFilterDialog(mutationsList) {
for (var mIdx = 0; mIdx < mutationsList.length; mIdx++) {
if (mutationsList[mIdx].addedNodes.length &&
mutationsList[mIdx].addedNodes[0].classList &&
mutationsList[mIdx].addedNodes[0].classList.contains('a-IRR-dialog--filter')) {
removeOperators();
}
}
}
function removeOperators() {
var anchors = document.querySelectorAll('#' + irRegId + '_row_filter_operators a');
for (var aIdx = 0; aIdx < anchors.length; aIdx++) {
if (filterOperatorsToRemove.includes(anchors[aIdx].textContent)) {
anchors[aIdx].parentElement.parentElement.removeChild(anchors[aIdx].parentElement);
}
}
}
observer = new MutationObserver(detectFilterDialog);
observer.observe(
document,
{
attributes: false,
childList: true,
subtree: true
}
);
}
removeIRFilterOperators();
The MutationObverver uses the detectFilterDialog function to detect when the filter dialog is added to the DOM. When that happens, the removeOperators function removes the specified options from the operator's list. All you need to do is update the filterOperatorsToRemove array to include the list of operators you want to remove.
If you're talking about the "Actions" menu, then yes - go to IR's attributes and enable/disable any option you want:

in Gigya, Unable to set attribute in "email" of Screen "Forget Password" in Screen-sets ID "Default-LinkAccounts"

I have the following js implemented in Gigya JavaScript Parameters:
onAfterScreenLoad: function(event) {
if ((ell = document.querySelector("#gigya-forgot-password-screen input[type=text][name=loginID]")) != null){
ell.setAttribute('type', 'email');
ell.setAttribute('placeholder', 'user#example.com');
ell.setAttribute('autocomplete', 'off');
}
},
I am able to use the above code to handle the fields of all other screen-sets EXCEPT this "Forget Password" screen (i.e. Screen ID: gigya-forgot-password-screen) in Screen-sets ID "Default-LinkAccounts".
It looks like the forgot password flow is triggered without a user session and independently of the information passed into the Email field on the login screen.
If it is, then how to implement this.
it seems the name of the field is different depending upon which screen you are using:
window.ell = document.querySelector("#gigya-register-screen input[type=text][name=email]");
window.ell = document.querySelector("#gigya-login-screen input[type=text][name=username]");
window.ell = document.querySelector("#gigya-forgot-password-screen input[type=text][name=username]");
so:
onAfterScreenLoad: function(event) {
var ell = null;
if ((event.currentScreen === "gigya-forgot-password-screen") || (event.currentScreen === "gigya-login-screen")) {
ell = document.querySelector("#" + event.currentScreen + " input[type=text][name=username]");
} else if (event.currentScreen === "gigya-register-screen") {
ell = document.querySelector("#gigya-register-screen input[type=text][name=email]");
}
if (ell != null){
ell.setAttribute('type', 'email');
ell.setAttribute('placeholder', 'user#example.com');
ell.setAttribute('autocomplete', 'off');
}
}

Angular 2 Pass Enum to Components Function from HTML

I have created an enum to open up a modal based on whether its an add or an edit modal.
enum ModalTypes {
Add,
Edit
}
public openManageModal(type: ModalTypes) {
if (type == ModalTypes.Add) {
//Open edit modal
}
else {
//Open add modal
}
}
I cant seem to figure out how to call this from HTML. I have tried various things such as openManageModal('Add'), but nothing seems to work. Clearly I can create a function in the component, and parse the string to an enum, but I think this way would be more appropriate. Any help would be appreciated.
Thanks
You should be able to call the function like this:
openManageModal(0) // for ModalTypes.Add
openManageModal(1) // for ModalTypes.Edit
The enum declaration will transpile to the following by the TypeScript compiler:
var ModalTypes;
(function (ModalTypes) {
ModalTypes[ModalTypes["Add"] = 0] = "Add";
ModalTypes[ModalTypes["Edit"] = 1] = "Edit";
})(ModalTypes || (ModalTypes = {}));
So it basically creates an object which looks like this:
{
0: "Add",
1: "Edit",
Add: 0,
Edit: 1
}
So as you can see ModalTypes.Add == 0 and ModalTypes.Edit == 1.

Zend 1 ajax with dojo informatiom person

I'm working with Zend 1 with dojo and do not know how to use ajax . In my particular case that when selecting a select , whether made ​​in consultation ajax back from the database information. To enter a ID from user print the information from user by ajax.In my work I can't use jquery.
Good question!
Not is very productive work with dojo, but is possible make exactly how do you want. You will create p element with information captured in data base
In your form, add attribute 'onChange'
$form->setAttrib('onChange', 'recoveryData()');
In js file do you have a function recoveryData(), something as:
dojo.require("dojo.html");
// clean data
var myNewElement = dojo.byId('myNewElement');
if (myNewElement != null) {
dojo.empty("myNewElement");
}
dojo.xhrPost({
content: {id: dojo.attr(dojo.byId("myElement"), "value")},
url: 'your-base-path/recovery-data/',
load: function (response) {
if (response != false) {
// converte to obj
var obj = dojo.fromJson(response);
// creat new element
var node = dojo.create("span", {
innerHTML: obj.NomeServidor,
id: "myNewElement",
'class': 'row'
}
);
dojo.place(node, dojo.byId("myElement"), "after");
}
}
});
Now, you need create an Action "recoveryDataAction()" in your Controller like this:
$data = $this->getrequest()->getPost();
$id = $data['id'];
if ($this->getrequest()->isXmlHttpRequest()) {
// disable layout
$this->_helper->layout()->disableLayout();
// disable view render
$this->_helper->viewRenderer->setNoRender();
$yourTable = new Project_Model_YourTable();
$row = $yourTable->fetchRow($id);
if ($infos != null) {
echo Zend_Json::encode($row);
return;
}
echo false;
}

set value of radcombobox from another combobox

set value of radcombobox2 from another radcombobox1
radcombobox2 is on asp usercontrol & radcombobox1 is on aspx page.
and value is coming from database on time of binding like this
if (result.IsSuccessful)
{
var rcbRadComboBox = (RadComboBox)RadGrid1.MasterTableView.FindControl("RadComboBox1");
if (comboEditAccessGroup != null)
{
comboEditAccessGroup.DataSource = result.Result;
comboEditAccessGroup.DataTextField = "Title";
comboEditAccessGroup.DataValueField = "JobId";
comboEditAccessGroup.DataBind();
}
}
but the problem is that ,i am not able to change selected index which is selected on radcombobox1
I have used
var selectedindexforjob = Request.QueryString["JobId"];
rcbRadComboBox.SelectedValue = selectedindexforjob;
for achieve goal but got failure nothing happens.
please help me.
Radcombobox1====is on aspx page
Radcombobox2=====is on ascx page
Thanks
Add a property to the user control:
public string ComboSelectedValue
{
get { return RadComboBox2.SelectedValue; }
set { RadComboBox2.SelectedValue = value; }
}
And then you can use this property from the page:
MyUserControl.ComboSelectedValue = RadComboBox1.SelectedValue;

Resources