Delete cookies using Selenium IDE - selenium-ide

I need to delete cookies using Selenium IDE. deleteCookie and deleteAllVisibleCookies don't work.

I got around that problem by adding the script and calling it before each test ( calling from the Selenium IDE "open yourdomain/clear_cookies.php" )
clear_cookies.php
<?php
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-100000);
setcookie($name, '', time()-100000, '/');
setcookie($name, '', time()-100000, '/', '.'.$_SERVER['HTTP_HOST']);
}
}

Related

How do I attach a pdf file to a Gravity Forms Notification?

Gravity forms offers a way to attach files from the file uploader (See code below), but how would I change this code to simply attach my own PDF file from either a hidden field value or simply paste the pdf file within this code? I tried a few things but it didn't work. Any help would be appreciated!
add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {
//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria, such as name
if ( $notification['name'] == 'User Notification' ) {
$fileupload_fields = GFCommon::get_fields_by_type( $form, array( 'fileupload' ) );
if(!is_array($fileupload_fields))
return $notification;
$attachments = array();
$upload_root = RGFormsModel::get_upload_root();
foreach( $fileupload_fields as $field ) {
$url = $entry[ $field['id'] ];
$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );
if ( $attachment ) {
$attachments[] = $attachment;
}
}
$notification['attachments'] = $attachments;
}
return $notification;
}
Based on that code, something like this should work. Replace the $url value with the URL to your PDF.
add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {
if ( $notification['name'] == 'User Notification' ) {
$url = 'http://yoursite.com/path/to/file.pdf';
$notification['attachments'][] = $url;
}
return $notification;
}

Getting a menu delivered via REST

I am trying to get a menu via REST and I've created a new module and rest resource plugin that allows for GET on /entity/restmenu/{menu_name}.
I can successfully return this example json using this function when I hit the URL.
public function get(EntityInterface $entity) {
$result = array();
for ($i = 0; $i < 10; $i++) {
$temp = array(
'title' => 'Test ' . $i,
'href' => '#/' . $i
);
array_push($result, $temp);
}
return new ResourceResponse(json_encode($result));
}
I cannot figure out how to load the menu based on $entity. If I hit my URL (http://dang.dev:8888/entity/restmenu/main?_format=hal_json) $entity's value is 'main' which is the machine name of the main menu.
I've tried using Drupal menu tree, but I am not having luck, and debugging this thing with only JSON responses is quite difficult.
How do I get menu item titles and paths based on the menu machine name?
EDIT
Ok, sort of figured it out.
public function get($entity) {
$menu_name = $entity;
$menu_parameters = \Drupal::menuTree()->getCurrentRouteMenuTreeParameters($menu_name);
$tree = \Drupal::menuTree()->load($menu_name, $menu_parameters);
$renderable = \Drupal::menuTree()->build($tree);
$result = array();
foreach (end($renderable) as $key => $val) {
$temp = array(
'menu_item' => $val,
'route' => $key
);
array_push($result, $temp);
}
return new ResourceResponse(json_encode($result));
}
Right now that will output:
[
{
"menu_item":{
"is_expanded":false,
"is_collapsed":false,
"in_active_trail":false,
"attributes":"",
"title":"Home",
"url":{
},
"below":[
],
"original_link":{
}
},
"route":"standard.front_page"
},
{
"menu_item":{
"is_expanded":false,
"is_collapsed":false,
"in_active_trail":false,
"attributes":"",
"title":"Communities",
"url":{
},
"below":[
],
"original_link":{
}
},
"route":"menu_link_content:139d0413-dc50-4772-8200-bc6c92571fa7"
}
]
any idea why url or original_link are empty?
This was the correct answer:
public function get($entity) {
$menu_name = $entity;
$menu_parameters = \Drupal::menuTree()->getCurrentRouteMenuTreeParameters($menu_name);
$tree = \Drupal::menuTree()->load($menu_name, $menu_parameters);
$result = array();
foreach ($tree as $element) {
$link = $element->link;
array_push($result, array(
'title' => $link->getTitle(),
'url' => $link->getUrlObject()->getInternalPath(),
'weight' => $link->getWeight()
)
);
}
return new ResourceResponse(json_encode($result));
}

Correct proxy script for html2canvas

I'm trying to get html2render ( http://html2canvas.hertzen.com/ ) to work on my website. It works for the basic stuff - but none of the images show (as they are on a cdn.domain.com subdomain).
I've been reading up, and it seems that it doesn't like other domains out of the box. I found a couple of PHP proxy scripts:
https://github.com/brcontainer/html2canvas-php-proxy
https://github.com/adjdred/html2canvas-proxy-php
I tried to get those going, but we don't have curl enabled on this server. So, I'm resorting to writing something in Perl.
Here is what I've got so far:
use MIME::Base64;
use File::Slurp;
handle();
sub handle {
print ('Access-Control-Max-Age:' . 5 * 60 * 1000);
print ("Access-Control-Allow-Origin: *");
print ('Access-Control-Request-Method: *');
print ('Access-Control-Allow-Methods: OPTIONS, GET');
print ('Access-Control-Allow-Headers *');
print ("Content-Type: application/javascript");
#print $IN->header;
my $url = $IN->param('url');
$url =~ s|https://cdn.xxx.net|/srv/www/xxx.net/www|g;
if (-e $url) {
my $file = read_file($url);
use JSON;
my $mime_type;
if ($url =~ /\.jpe?g$/i) {
$mime_type = "image/jpg"
} elsif ($url =~ /\.png$/i) {
$mime_type = "image/png"
}
print JSON::encode_json([{
"pathinfo" => $url,
"error" => undef,
"data" => encode_base64($file),
"mime_type" => $mime_type
}]);
} else {
print "ACK!";
}
}
However, it still doesn't work :( There is little (none??) documentation on the proxy (apart from telling you that you need it in some cases!)
Can anyone share what the outputted data should look like? I tried to work it out based on the above example codes , but my PHP is a bit rusty (and I don't have a server with PHP and Curl enabled, that I can test it out on)
Thanks!
Ok, well not so much an answer about the proxy - but I did come across a post:
HTML2Canvas with CORS in S3 and CloudFront
In here, is shows an example of using:
useCORS: true,
... so I tried that:
html2canvas(document.body, {
useCORS: true,
onrendered: function(canvas) {
}
});
...and it works!!!!
In my instance, I was just using domain.com and cdn.domain.com as the CDN. If you are using other 3rd party CDN's, you may need to look at enabling the CORs headers.

How to test for a redirect in Mojolicious?

I want to test a page with a form which, when submitted, will redirect to the resulting page for the submitted item.
My Mojolicious controller contains:
sub submit_new {
my $self = shift;
my $new = $self->db->resultset('Item')->new( {
title => $self->param('title'),
description => $self->param('description'),
} );
$new->insert;
# show the newly submitted item
my $id = $new->id;
$self->redirect_to("/items/$id");
}
The test script for this controller contains:
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('MyApp');
my $tx = $t->ua->build_form_tx('/items/new/submit' => $data);
$tx->req->method('POST');
$t->tx( $t->ua->start($tx) )
->status_is(302);
My issue is that it stops with the 302 status. How do I proceed with the redirect so I can verify the resulting item page?
Set the matching setting from Mojo::UserAgent:
$t->ua->max_redirects(10)
Also, you don't need to build the form post manually:
$t->post_form_ok('/items/new/submit' => $data)->status_is(...);
Reference:
http://mojolicio.us/perldoc/Test/Mojo#ua
http://mojolicio.us/perldoc/Mojo/UserAgent#max_redirects
http://mojolicio.us/perldoc/Test/Mojo#post_form_ok
You could also (and probably should) test the content of the landing page to which the successful login has redirected :
my $tm = '' ; # the test message for each test
my $t = Test::Mojo->new('Qto');
$t->ua->max_redirects(10);
my $app = 'foobar';
my $url = '/' . $db_name . '/login' ;
$tm = "a successfull result redirects to the home page";
my $tx = $t->ua->post( $url => 'form' => {'email' =>'test.user#gmail.com', 'pass' => 'secret'});
ok ( $tx->result->dom->all_text =~ "$app home" , $tm );
the docs for how-to get the content with mojo dom
the mojo dom selector syntax doc link
an example testing script with login testing

How to remove login form from this CGI::Application example?

In this tutorial he creates a custom login form, just to show how it is done. Please search for
How do I remove the custom login and fall back to the default?
To code looks like this
sub cgiapp_init {
my $self = shift;
my %CFG = $self->cfg;
# ...
$self->authen->config(
DRIVER => [ 'Authen::Simple::LDAP',
host => '',
basedn => '',
],
STORE => 'Session',
LOGOUT_RUNMODE => 'logout',
LOGIN_RUNMODE => 'login',
POST_LOGIN_RUNMODE => 'okay',
RENDER_LOGIN => \&my_login_form,
);
$self->authen->protected_runmodes(
'mustlogin',
);
}
sub login : Runmode {
my $self = shift;
my $url = $self->query->url;
my $user = $self->authen->username;
if ($user) {
my $message = "User $user is already logged in!";
my $template = $self->load_tmpl('default.html');
$template->param(MESSAGE => $message);
$template->param(MYURL => $url);
return $template->output;
} else {
my $url = $self->query->self_url;
unless ($url =~ /^https/) {
$url =~ s/^http/https/;
return $self->redirect($url);
}
return $self->my_login_form;
}
}
Update
Here is mentions that CGI::Application have a default login that looks better than his.
Line 159 specifies a subroutine to use
to generate a login form. Note that
the Authentication plugin comes with a
default form that you can use. I'm
including this one just to demonstrate
how to go about creating one of your
own, in case you really want to. The
default one actually looks much better
than mine, so you might wish to
comment out line 159!
I'm the author of that tutorial. Sorry for the confusion!
What I should have said is "comment out lines 157, 158, and 159 of Login.pm".
To use the default form that's built in to the CGI::Application::Plugin::Authentication module, you don't need to specify LOGIN_RUNMODE, POST_LOGIN_RUNMODE, or RENDER_LOGIN.
Those are all provided just to help you customize your login page. I included a customized
version in the tutorial thinking that most people would need to know how to do so.
The default one actually looks much better than mine, so you might wish to comment out line 159!
Comment out line 159.