How to input generated CAPTCHA Text in text field using cypress test? - automated-tests

How to input generated CAPTCHA Text in text field using cypress test.
I need a example script_spec.js enters email, passsword and CAPTCHA Text for successfully login
//Home page
cy.visit('http://someurl.com');
//Login
cy.contains('Log in').click();
cy.url().should('eq', 'http://someurl.com'); // => true
cy.get('#Email').type('me#url.com');
cy.get('#Password').type('password');
//Enter CAPTCHA Text in text field here(TODO..)
cy.contains('Log In').click();
//SUCESSFULLY
cy.url().should('eq', 'http://someurl.com'); // => Home page true

I would have an environmental variable in your backend (ex ENV=test). When you run the application pass in that environmental variable. And where the capcha validatation happens do
passed = ENV===‘test’ || actualValidation
So whatever you pass it in the test environment it will accept. Then just pass it “anyrandomvalue”.
In production it will fall back to actual validation

Related

Submitting form item via code not triggering an email notification

I am trying to submit a new form item via api on my MVC web app (grabbed the code from form's code tab) but the email notification is not working. It did create a new record except for the email alert. I checked the email queue but no records of the form item. I configured the smtp server settings properly. I checked the event logs as well but I dont see any errors. Am I missing something or this feature is only on portal engine?
Apparently if we do the submission of form manually via code and not using the default mvc form widgets it does not trigger the notification automatically. We also need to send the notifications via code. form data documentation
// Gets the form object representing the 'ContactUs' form on the current site
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);
if (formObject != null)
{
// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string formClassName = formClass.ClassName;
// Creates a new data record for the form
BizFormItem newFormItem = BizFormItem.New(formClassName);
// Sets the values for the form's fields (UserMessage in this case)
newFormItem.SetValue("UserMessage", "This is a message submitted through the API.");
// Saves the new form record into the database
// Set values for all 'Required' fields in the form before calling the Insert method, otherwise an exception will occur
newFormItem.Insert();
// Obtains a factory object used to create a form notification sender service for the given form
IBizFormMailSenderFactory senderFactory = Service.Resolve<IBizFormMailSenderFactory>();
// Creates an instance of the form notification sender for the inserted form item
IBizFormMailSender sender = senderFactory.GetFormMailSender(formObject, newFormItem);
// Sends a notification email to users (as specified on the form's 'Email notification' tab)
sender.SendNotificationEmail();
// Sends a confirmation email to the submitter (based on the form's autoresponder settings)
sender.SendConfirmationEmail();
}

Adding users and attributes programatically in Concrete5 version 8

Hi I have recently followed some documentation to create new users from a csv file programatically. According to the Concrete5 docs/api there was method called getByID( $uID ) but this has since be deprecated!
I am creating a new user like so:
$userRegistration = Core::make('user/registration');
$file = fopen("test-users.csv","r");
while (($data = fgetcsv($file)) !== FALSE) {
echo "email address " . $data[0];
$userRegistration->create([
'uName' => $data[0],
'uPassword' => $data[1],
'uEmail' => $data[2],
'uIsValidated' => true,
]);
}
However if I want to add a value to an existing non-core attribute for instance lets call it user_county then how would I change this after programatically adding the user? I may need to do this for several user attributes as well so the values would need to come from the CSV and automatically be looped through to apply the correct value to the corresponding attribute whether it is blank or filled.
The create() method will return a UserInfo object (Concrete\Core\User\UserInfo) after successfully adding a new user. With the returned UserInfo object, you can use the setAttribute() method to set your custom user attribute.
Make sure that you have created the customer user attribute first and check that it is available before setting it, otherwise setting it will throw an error. I believe you can do this using Concrete\Core\Attribute\Key\UserKey::getByHandle('my_user_attribute') and seeing if it returns an object.
The create() method is in the RegistrationService class:
https://github.com/concrete5/concrete5/blob/develop/concrete/src/User/RegistrationService.php#L51-L140

Custom AEM Form field not persisted

I attempt to create a custom field for AEM form (AEM6.0 SP3) following how text field does it: /libs/fd/af/components/guidetextbox
I created init.jsp and widget.jsp with same content.
On widget.jsp, I then add some jQuery to autopopulate text field on focus out.
<script>
var thisField = '${guideid}${'_widget'}';
$(thisField).focusout(function() {
$(this).val('date ' + new Date());
});
</script>
On focus in, I type text 'ABC' then when focus-out I get text 'date ' however when submitting the data, text 'ABC' gets submitted.
Is there any AEM API I need to invoke (instead of just jQuery .val() function) in order for the changes to be recorded ?
Not the best solution, but we managed to get it work by first calling focus(), eg.
$(this).focus().val('date ' + new Date());
Better solution:
create a custom function eg
function initDatePicker(thisObj) { $(this).focusout(function() {thisObj.value = $(this).val();});}
Update .content.xml to call this within initScript eg.
<cq:template guideNodeClass="guideTextBox" jcr:primaryType="nt:unstructured" jcr:title="Datepicker input field" initScript="initDatePicker(this)"/>
the function will be immediately included when the widget is added to canvas.
In AEM Forms a Javascript model is maintained that stores the value and that model is used to submit the data. Now to pass on the value from the ui to the model XFA_EXIT_EVENT[1] has to be triggered. So after setting the value you must add this line of code to persist the value
$(this).trigger(xfalib.ut.XfaUtil.prototype.XFA_EXIT_EVENT)
Also a better way would be to create your own widget for this specific scenario. See [2] for more details. The article is for AEM Form 6.1 but it will work for AEM 6.0 as well.
[1] https://helpx.adobe.com/aem-forms/6/html5-forms/introduction-widgets.html
[2] https://helpx.adobe.com/aem-forms/6-1/custom-appearance-widget-adaptive-form.html

Is it possible to transfer data retrieved using facebook Graph API to a database in ASP.NET?

I have an ASP.net Web project that includes a form and a Database.
When a user register to the site (not from facebook) he has a username, and then when he fills the form, I can add this username to the 'username' column in the database (using User.Identity.Name). When he login using facebook, I can't do it. So I thought to use his facebook ID, since any ID is different, but I can't find a way to do it. I tried to retrieve the ID using response.id, set the value in a Label, and then to get the Label content from the codebehind to transfer it to the DB, but it didn't work. here is the code I tried:
Set the ID into the label:
function testAPI() {
FB.api('/me?fields=name,email,gender,age_range,picture.width(45).height(44),location', function (response) {
console.log('Successful login for: ' + response.name);
document.getElementById('HiddenFacebookID').innerText = response.id;
});
}
The Label:
<asp:Label ID="HiddenFacebookID" runat="server"></asp:Label>
The code-behind:
conn.Open();
string insertQuery2 = "INSERT INTO UserData (username) values (#username)";
SqlCommand com2 = new SqlCommand(insertQuery2, conn);
com2.Parameters.AddWithValue("#username", HiddenFacebookID.Text);
com2.ExecuteNonQuery();
The Label content is really the facebook-ID, but the database gets NULL. Please Let me know if I wasn't clear.
I will appreciate any help, thanks!
The value you're setting in JavaScript isn't being posted back to the server. Only form values are posted to the server. And an asp:Label doesn't render as a form element.
Use a hidden form field instead:
<asp:Hidden ID="HiddenFacebookID" runat="server"></asp:Hidden>
And set its value in JavaScript:
document.getElementById('HiddenFacebookID').value = response.id;
Basically, regardless of the lies that WebForms has been telling for years, HTML content is not posted to the server when submitting a form :) Only form values are.

vbscript server side validation

Basically I have a page named dvds.asp with a form that goes to action="process.asp". The process.asp script validates the Name, Surname and Email fields. I would like that if the email does not exist, a redirect will occur to the original page (dvd.asp) and also display a custom error.
The validation of the email field and redirect I know how to do. The only problem is how I am going to get the custom error value in the dvds.asp.
Any help please? :)
FYI:
I am using this code in process.asp to validate:
if txtEmail = "" then
Server.Transfer(Request.ServerVariables("HTTP_REFERER"))
else
Now the error I want to show on the dvds.asp page is: "Please fill in your email" .. How I can do that please?
Hard to say without seeing any source, (For instance, how are you validating the email? What is this "Custom error value"?
Assuming you have a function that validates the email and returns false if it fails and the matching error value is "1" then you could simply include this in your redirect:
Dim EmailAddress
EmailAddress = Request.Form("EmailAddress")
If ValidateEmail(EmailAddress) = False Then
Response.Redirect("dvd.asp?ErrorID=1")
End If
and on the Origional Source page, you could just display errors back to the user as follows:
'#### Output errors
If Trim(Request.QueryString("ErrorID")) <> "" Then
Select Case Request.QueryString("ErrorID")
Case "1" ' #### Email Error
Response.Write("<p><span style=""color: red"">Error: Invalid email address</span></p>")
Case "2" ' #### Bad Name
Response.Write("<p><span style=""color: red"">Error: Invalid Name</span></p>")
Case Else
Response.Write("<p><span style=""color: red"">Error: Unknown / Generic Error</span></p>")
End Select
End If
One small suggestion by the way, its often preferable for pages such as this to post to the same page and include any email functionality you need from a class / SSI. That way you cold auto-populate the form again if an error occurred rather than expecting your end user to re-type the whole form if they get an error.

Resources