Can be switch var webdrriverio from require('webdriverio ') to require('webdriverjs-angular') in the same script - webdriver-io

We have the application where the login page is Non Angular and the other pages uses angular. If we start the var webdriverio = require('webdriverio'), we are able to script but we wanted to use mocha and chai for our scripting, so the best way is to use require('webdriverjs-angular') for Angular pages. I tried using require('webdriverjs-angular') for login page and gets timeout as excepted. I tried protractor where I was able to switch and we had other issue in locating element inside iframe so we switched to webdriverio. Please can you help us and let us know can we switch the require from webdriverio to webdriverjs-angular in the same code. If yes, please provide the sample code

Related

Vue js - How can i show API request in terminal of vs code?

How can i show API request in terminal of vs code?
So i'm using vs code and i would like to my API response in terminal.
for example
GET -> API URL -> Status code
for each page that i enter.
Programatically if you wanna print the response in your terminal then you need to something like
axios().then(resp => console.log(resp));
If you wanna test your api's from within VSCode then do
Check this out a VSCode extension
https://www.thunderclient.io
I am not sure if their is anyway possible for you to fetch data from API on the terminal of VScode. Unless you can create your won Vs Code plugin to handle on the same.
Check out this article, it will help you with that.
https://blog.bitsrc.io/vs-codes-rest-client-plugin-is-all-you-need-to-make-api-calls-e9e95fcfd85a

How can I make testcafe to copy and use same headers as the actual website?

I am running testcafe tests on an authentication page and I can see that testcafe is modifying/removing/adding the headers when sending the requests to the website and this is blocking me to do 2FA on this page
As soon as I got the issue, I tried to do the automation with Selenium just to confirm it is testcafe issue. As selenium doesn't create a proxy to insert the js scripts and automate the website I could do the automation with selenium, but I want to use testcafe as the site is developed in react.
await t.typeText(this.emailInput, config.userEmail)
.click(this.nextButton)
.typeText(this.passwordInput, config.userPassword)
.click(this.nextButton)
.click(this.otpOption)
.typeText(this.otpInput, this.token)
.click(this.signinButton)
}
When clicking on the next button I should have the 2FA form asking for the code, but I got a page saying was not possible to do the authentication (Something wrong happened) and I saw the response code for the BeginAuth endpoint was 222 without any response instead of 200.
The URL is that I am using to authenticate looks like this one:
https://login.microsoftonline.com/client uuid/oauth2/authorize?response_type=code%20id_token&response_mode=form_post&client_id=client uuid&scope=openid&x-client-Ver=4.0.0
Testcafe team found out this is a bug on testcafe-hammerhead, they have fixed and it is going to be included in the next release.
https://github.com/DevExpress/testcafe-hammerhead/issues/2052
For now I am generating the cookie in the automation and sending it in the header.

Is it possible to run selenium rc code in 2 different URLs?

The AUT contains the login page which validates the user credentials. Once successful, the user needs to hit a new URL in a new tab to access the actual application.
Is it possible to automate the above scenario using selenium RC?
Yes it's possible, but I'd recommend using Selenium WebDriver as it's the current version. Selenium RC is very old.
Using Selenium WebDriver:
driver.navigate().to("http://aut/login");
driver.... // login logic like setting the user/pass clicking login.
...
driver.navigate().to("http://somenewurl.com");
// continue testing here...
If you are adamant on remaining with Selenium 1 (which i could understand if you already have a big suite in it..):
selenium.open("http://aut/login");
selenium... // login logic here
...
selenium.open("http://somenewurl.com");
// continue testing here.

Anti forgery token and web testing

I am trying to do a web test in VS2012 for an MVC site.
One of the scenarios is to login and go through a list of products, select the one you want and follow through to the purchase page.
Problem is that when the web test is run, I get an error about the anti forgery token and that it does not match.
How on earth is it possible to do the testing with the anti forgery token? The user must login - there will be thousands of users for the load test (eventually) but need to make it work for 1 user first.
the login view/action does do an AntiForgeryToken in the view and validation on the controller.
any advice and tips are appreciated.
Once you run your script and it fails, go to the call proceeding the one that fails.
Go to the response tab
In the body, find the __RequestVerificationToken name which is in an input tag and extract everything in between the value attribute.
Select the value and right click > add extraction rule and press OK.
You will find an Extraction rules folder and underneath it, the Extraction rule we just created. Feel free to rename the Context Parameter Name.
Go to the next page , which should be the one that failed, and find the Form Post Parameter named "__RequestVerificationToken". View it's properties
Bind it to the Context Parameter Name created previously. To do so, view the properties of this post parameter and set the "Value" to be:
{{Name Of Context Parameter}}
(Include the 2x curly braces)
Press enter to confirm/save
Next time you run the script - all works
This is how it worked for me...
I was seeing a similar problem. After recording a web test script, the script would fail at the point of log-in on with the following message:
The provided anti-forgery token was meant for user "Domain\UserName", but the current user is "".
The solution was to set the PreAuthenticate property to false in the test properties. By default the web tests will pass an authentication header to the server which was being used in the generation the token.
I am not familiar with "web testing in VS2012" but as I know "Anti-Forgery Token" requires sending the token from browser to the server back.
I had an experience with Selenium-Webdriver and suggest you use it because it provides an API to interact with supported browsers as real user does.
You can easily start using Selenium WebDriver if you add Selenium WebDriver 2.37.0 NuGet package to you test project.
Selenium-WebDriver makes direct calls to the browser using each
browser’s native support for automation. How these direct calls are
made, and the features they support depends on the browser you are
using.
Selenium-webdriver currently supports the following drivers:
Chrome
Internet Explorer
Firefox
Opera
HtmlUnit
Android

PhantomJS and jquery screen scraping - no output

I am attempting to do screen scraping using phantom js.
I have copied some phantomjs code from this site: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery
Starting with that script, I have modified into this: http://jsfiddle.net/dqfTa/ (see javascript)
My aim is to collect the prices from a website, which are the inner html of the ".price" tags, into a javascript array. Right now I am trying to console.log() them to my screen.
I am running phantomjs v1.6 and jquery v1.8 through the ubuntu 12.04 console. I am setting the user agent to "iPhone".
Here is my output:
nwo#aws-chaos-us-w-1:~/sandbox$ phantomjs usingjqueryandphantom.js
hello
success
============================================
Step "0"
============================================
It never gets past step 0. Take a look at my code, I did a console.log("h1"); but it won't output it. What am I doing wrong here?
Phantomjs requires you to hook into the console output coming from it's page context. From the API reference:
This callback is invoked when there is a JavaScript console message on
the web page. The callback may accept up to three arguments: the
string for the message, the line number, and the source identifier.
By default, console messages from the web page are not displayed.
Using this callback is a typical way to redirect it.
page.onConsoleMessage = function(msg) {
console.log("This message came from the webpage: "+ msg);
};