URL re-direction issue - robotframework

I am validating a few URL's together using data driver and some are getting redirected still prints 200 response. In this case, the test case needs to fail and mention the reason for failure.
Any leads would be appreciated.
Code snippet:
create session current_session ${URL}
${Response}= get request current_session /${gmail}
Here, I need to verify, if the URL has navigated to right page without any redirection. I using the data driver library.

I think you should separate your test cases. You should have one (or more) for verifying the response body and another one for verifying the URL redirection.
For the latter one I would definitely use SeleniumLibrary.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Redirect Test
Open Browser https://stackoverflow.com/ Firefox
Location Should Be https://stackoverflow.com/
[Teardown] Close Browser
But if you would like to use RequestsLibrary for that one as well, the returned object has an url and a status_code attribute that could be used for verification.
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Redirect Test With Requests
Create Session SO https://stackoverflow.com/
${response}= Get Request SO /tags
Log ${response.status_code}
Should Be Equal As Integers ${response.status_code} 200
Log ${response.url}
Should Be Equal As Strings ${response.url} https://stackoverflow.com/tags
[Teardown] Delete All Sessions

Related

JMeter: The purpose of User-defined Cookies for requests

I'm just trying to get going with JMeter, and I try to understand more about User-defined cookies.
What purpose do they fulfill when you add them with hard-coded values, like for instance if you define a cookie called A and give it a value B to a certain domain for your HTTP sampler?
Much grateful for all information!
There could be several possible reasons:
Replay user session without having to re-login (i.e. session hijacking) so you would be able to debug your test by running a single request rather than the whole sequence (open login page, login, navigate somewhere, do something, etc.)
The value doesn't have to be hard-coded, it may come from correlation or calculation by the JSR223 Pre-Processor
Negative test scenarios (providing invalid cookie value to check for anticipated error)
You name it
Some web sites have Javascript scripts executed on page load which are adding/removing/updating HTTP cookie(s)
The set() method of the cookies API sets a cookie containing the specified cookie data. This method is equivalent to issuing an HTTP Set-Cookie header during a request to a given URL.
JMeter isn't executing Javascript
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages.
So in JMeter you can manually manipulate HTTP cookie as you expect your site to execute

In JMeter, Getting "Object moved here" response for login post request while performing Load test in Asp.net Web app

I have performed Load testing in Asp.net application using JMeter. While login, am getting "Object Moved Here" message as response.
In View result tree, I found Login main sampler displaying with two sub samplers.
In that one sub sampler is with the "Object Moved Here" message.
In my test plan, I have handled
- CSS/JQUERY Extractor to extract dynamic values "Event validation" & "View State"
- HTTP Cookie manager(Checked "Clear cookies each iteration" & Cookie policy: Compatibility)
Note: Except the Login functionality request & response, all the other HTTP samplers in my test plan are worked as expected.
Anybody have any solution for this?
Well-behaved JMeter test should do exactly what real browser is doing, to wit:
send the same HTTP requests as real browser does
handle "embedded resources" (images, scripts, styles, fonts) like real browser does
properly mimic AJAX requests
simulate browser headers, cache and cookies
In particular your case Object moved here request stands for a HTTP Redirect, to wit first request gets 3xx status code and being pointed to another location.
You should verify what real browser is doing using Network tab of its developer tools and ensure that JMeter is doing the same. If the browser is not doing the redirect you can explicitly tell JMeter not to follow the redirects by unticking Redirect Automatically and/or Follow Redirects boxes in the HTTP Request sampler

How to share tests/steps in Robot Framework?

Sorry for the trivial question, but how to share steps in Robot Framework (pyCharm)? I have a test case that covers loging into account (login.robot) and another test case that conducts an action after logging in. How do I use the steps from first case so I don't have to write them again? Should I put them in 'Resource' file? Or set as resource that case 'login.robot'? Or maybe put it in 'Keywords'?
Thanks in advance for the help!
You need to create a keyword to perform login and use it in both of your test cases. In second test case the keyword could be part of setup. Below is just a rough exmaple
*** Settings ***
Library Selenium2Library
Resource C:\\development\\robot-scripts\\sshlibrary\\login.robot
*** Test Cases ***
Open the Login Page of Yahoo Mail
Open Login Page
Close Browser
Resource File
*** Settings ***
Documentation An example resource file
Library Selenium2Library
*** Variables ***
${HOST} mail.yahoo.com
${LOGIN URL} https://${HOST}/
${BROWSER} gc
*** Keywords ***
Open Login Page
[Documentation] Opens browser to login page
Open Browser ${LOGIN URL} ${BROWSER}
Wait Until Page Contains Element //*[#id="mbr-login-greeting"] timeout=60s
As advised, please go through the robotframework user guide for this.

Check the existence of remote directory with R

I would like to check whether a given directory exists in a remote server, given the URL pointing to that directory. For example:
url <- "http://plasmodb.org/common/downloads/release-24"
How can this be accomplished in R? I have considered using url.show, which downloads and shows the url if it exists but gives an error in the case of a non-existent directory. But I am not sure what would be the best approach, optimally without having to download the whole URL in the case of an existing directory.
This will be highly dependent on the server/resource in question since it has more to do with HTTP status codes than R capability. Provided a remote server is configured to respond properly to directory index requests you can use HEAD from httr for this:
library(httr)
status <- HEAD("http://plasmodb.org/common/downloads/release-24/")
status$status_code
## [1] 200
status <- HEAD("http://plasmodb.org/common/downloads/release-100/")
status$status_code
## [1] 404
Here's a nicely-formatted list of status codes http://httpstatus.es and here's a salient RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html that you should also peruse other sections of. Finally, here's a Wikipedia link http://en.wikipedia.org/wiki/Webserver_directory_index discussing the "directory index". That shows you may also get a 403 vs 200 or 404 depending on the config (and it's really not limited to that depending on the web server).

wp-piwik configuration fails for multiple reasons

I had a working wp-piwik plugin. Its configuration looked like this:
It worked fine. Then I moved the piwik installation to a different location (so I can track more sites).
Now wp-piwik only recognizes the auth key if we're not using a /home... path, but http://analytics... path. And unfortunately it doesn't work - no tracking occurs.
If I give a wrong URL, it sees it's wrong.
If I supply a wrong auth token, it sees it's wrong. So somehow the plugin communicates with piwik.
If I supply piwik location as a /home/piwik/, it doesn't work, and I'm pretty sure it used to work before I updated from 2.3.0 to 2.7.0.
My site works fine with the tracking code. But that is visible in the browser and I don't like that. I don't want the tracking to depend on the user's browser. I don't want the client to know that there's tracking.
If there's manual php code inclusion that I can use. I'd use it, but i'm not very good with php.
The option "Piwik path (PHP API, beta):" works only if I remove the auth token but also doesn't track. the piwik path can only be /home/piwik....
Here's what Support --> "Run test script" gives me:
*** Test 1/2: SitesManager.getSitesWithAtLeastViewAccess ***
Using: cURL
SSL peer verification: enabled
User Agent:
Call: /home/user/piwik_location/?module=API&method=SitesManager.getSitesWithAtLeastViewAccess&format=XML&token_auth= + TOKEN
Result:
Time: 0s
*** Test 2/2: SitesManager.getSitesIdFromSiteUrl ***
Using: cURL
SSL peer verification: enabled
User Agent:
Call: /home/user/piwik_location/?module=API&method=SitesManager.getSitesIdFromSiteUrl&url=http%3A%2F%2Fsite.com&format=XML&token_auth= + TOKEN
Result:
Time: 0s
Any suggestions?
You also have to update the trusted hostname if you move Piwik:
http://piwik.org/faq/troubleshooting/faq_171/
If this does not help, check WP-Piwik's debug script output (see support tab in settings menu).
UPDATE: As discussed here (https://wordpress.org/support/topic/wp-piwik-recognizes-the-key-but-doesnt-track-with-piwik-url-or-piwik-path?replies=7), the plugin's behavior is as expected. The test script output above shows the wrong value for Piwik URL (it contains the path instead). If entering the Piwik URL and enabling the tracking script, the tracking works.

Resources