Cypress test fails but works when tested manually - cypress

I am trying to test the ability to retrieve results from a database. When running a test that logs in, navigates to the search tab and searches a word, I am getting a 401. If I go to the website, use the same log in information and do the exact same steps, it works perfectly. Here's the last few steps of the test:
cy.contains('Search').click(); //open tab
cy.contains('Search by').click();
cy.contains('Name').click();
cy.get('.search-field').type('Jane');
cy.get('.search-btn').click();
There's a drop down menu for what you want to search by, a textfield for the search word and a search button. I can't share all of the code but I can see from the video that logging in and all the following steps are performed as supposed to. What kind of things can cause a cypress test to return different results as opposed to manually performing the action? I added wait(2000)'s in between the steps but it made no difference.

Maybe there is an event that needs to be triggered before the page is able to search.
Take a look at the element you are typing into in the devtools, under the Event Listeners tab.
For example, the StackOverflow search box has an event for s-popover:show listed there - if testing that you would .trigger('s-popover:show') to fire that event and display the instruction tooltip.
So try something like this
cy.get('.search-field')
.type('Jane')
.trigger('change') // or .trigger('input')

Cypress deletes localStorage in between tests. In this case that deleted the authorization token which is why I was getting the 401. I installed this package: https://www.npmjs.com/package/cypress-localstorage-commands
After the log in I use
cy.saveLocalStorage();
And before making search
cy.restoreLocalStorage();

Related

How do I programmatically login through Auth0 Lock interface?

I'm trying to write a WebPageTest custom script that involves programmatically logging into my web app's Auth0 Lock interface as the first step but haven't been able to get it working.
I set up a private WebPageTest server to get a closer look at what was happening, and from the server logs it looks like the WebPageTest script is setting the value of the username/password fields and clicking submit using vanilla DOM manipulation (i.e. querySelector, click, etc.) but upon form submission, Auth0 Lock doesn't recognize that anything has been filled out in those fields. There's errors saying those fields can't be blank when submit is clicked.
I've used a local WebPageTest Node agent with my private server to successfully login through the Lock widget but don't know how to get performance logs using that approach (no results show after I get to the test results page). That login approach seems to work because the values going into the input fields get programmatically "typed in" through the WebDriver sendKeys function.
I came across this related post on Auth0 forums but don't know how I can incorporate what's being recommended there in the context of a WebPageTest script.
You can reproduce the problem I'm experiencing by going to the Auth0 Lock sample at the top of this page and running the following code in your devtools console:
document.querySelector('.auth0-lock-input[name=email]').value = 'hello#hello.com';
document.querySelector('.auth0-lock-input[name=password]').value = 'testing';
setTimeout(() => document.querySelector('.auth0-lock-submit').click(), 1000)
I expect to be able to programmatically enter input field info and submit it through the Auth0 Lock widget but haven't been able to do so. Does anyone have a solution to this?
The login page uses javascript/ajax to create the login form and its input elements. You're simply doing stuff too fast, not waiting for the elements to be created first, in order to populate and submit them. Just wait for the form and its input elements to become available/visible and then continue your login process.
Also, avoid using Sleep() / setTimeout() approach to tackle waitings. It's just wrong and it's a problem waiting to materialize itself, as soon as you change the environment in which your code is running. Use a proper waiting methods from your test framework and properly wait for those elements to become available.

Google Tag Manager isn't tracking mobile click to calls

I am trying to track clicks on the phone number on the website. After I set up the trigger using following settings:
Trigger Type: all elements;
Page URL: contains "tel:" ;
Click Text: contains "13";
With these settings, the trigger is firing correctly on the desktop but isn't working on mobile.
I tried to use only "Page URL"/"Text Only"/"Form Text"/"Form contains" as conditions for the trigger to fire, but all attempts are unsuccessful. I also tried to use "Just Links" as a trigger type but it's not helping.
I also tested the URL in different mobile browsers (chrome/safari) and emulator. With an emulator, the tag is firing correctly but it's not working on the
Please have a look at the preview to see the page and tracking I am talking about:
https://www.googletagmanager.com/start_preview/gtm?uiv2&id=GTM-T92J432&gtm_auth=MmNY2ZtOefQOp1Kce4yUFQ&gtm_preview=env-5&gtm_debug=x&url=https://lp.acfc.com.au/good-credit
I appreciate your advice on what is the problem and how it can be fixed.
Thanks!
Kirill
Actually, better way of doing this to set generic trigger in GTM, then you will be able to track any phones on your website:
1) Enable built-in variable Click Element (if you already have it, you can skip this step)
2) Create trigger, which will fire for all links which have tel:***** (it can be any phone).
CSS selector on the screenshot is a[href*="tel:"]
3) Create a tag, which will send data to GA
4) Check your events in GA.
Keep in mind that it might take a couple of hours to appear in Behaviour-> Events tab. Or you can check it immediately in Real Time -> Events tab
RESOLVED:
I just found out that in order to identify an event it is safer to look at how the data layer is changing after the action rather than on the "Variable" tab.
By doing so, you can see what data is actually going to google analytics, and it is more stable to use it as an ID for a trigger to fire.
In my case, I've had only elementURL that was pushed back to the datalayer. I used the parameter elementID equals "tel:xxxxxx" to make the tracker work. Hope it will help (just put your number instead of x).
Cheers!

Simple Coded UI login test on remote server

I used Microsoft Test Manager to create a test for a log on page (not locally hosted) and recorded this. All steps were executed without errors.
Then I've created a Coded UI test project in Visual Studio 2013.
I added a Coded UI Test with the existing recording.
I ran the test and I got the message below:
"FailedToPerformActionOnHiddenControlException: Cannot perform 'SetProperty of Text with value " on the username field.
I received this message when using the existing recording, but also if I record using the recording function in Visual Studio.
Has someone got experience with Coded UI Tests and maybe give me an example as to how to set it up.
If I understand correctly, you're basically trying to have Coded UI input a value into an HtmlInput control that's a text box on a web page. The error message "FailedToPerformActionOnHiddenControlException: Cannot perform 'SetProperty of Text with value" normally means that the value you're trying to submit isn't able to be taken by the control, either because a value isn't accepted (example, numeric values in a name field) or because it's more characters than can be accepted by the field. It could also be that the recording isn't defining the object properly, and that the property Text isn't an option on the control that was found.
So, confirm these three things:
1. The control you're tying to send value to is actually an HtmlInput. You can't send the Text property to, for example, an `HtmlDiv`.
2. The value you're submitting is a valid value for your control (you're not trying to submit numbers, for example, into a field that won't accept them).
3. The value you're submitting is within the length limit for the field.
If I were a betting man, I would say that you probably don't have the object defined properly. Take a look at the SearchProperties of the control in question first and make sure that it matches the HTML on the page itself.
Do I need to set a standard environment for testing on an other server.
I develop the Coded UI test project in a workspace on a development environment, but I need the tests to be run on a acceptation environment (the recorded tests are executed on the acceptation environment).
I read it's easy to setup this environment though, but what is best practise?
Is it better to execute it on the same environment?
Here's a code snippet:
[TestMethod]
public void TestLogonToAccount()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
this.UIMap.Enterusername();
this.UIMap.Enterpassword();
this.UIMap.Clickonlogin();
this.UIMap.ClickonCentral();
this.UIMap.Searchforemailaddress();
this.UIMap.Clickonlogin1();
}
I forgot an important part regarding the login recording test in MTM.
I just tried to play the steps again and got this error:
Playback of the selected sections of the action recording could not be completed The playback failed to find the control with the
given search properties. Additional Details: TechnologyName: 'MSAA'
Name: '' ClassName: 'MozillaWindowClass' ControlType: 'Window'

how to write queries in Hive Web Interface

I was playing around with hwi, I got it started.Now I can see the different schemas which are present. But I don't know how to query them. I tried to check hive wiki (https://cwiki.apache.org/confluence/display/Hive/HiveWebInterface) but they dont seem to have much information put over there. There seems to be a Running a query section in Walk through but it says image not found.
Anybody who has used HWI to query please suggest a way to use it.
Try these steps :
Open HWI : http://localhost:9999/hwi/index.jsp
Click on Authorize in the left pane. This will open the Change User Info section. Enter the username and hit submit to complete the authorization process. Upon successful authorization you'll see Authorization is complete at the top of your page.
Now click on Create Session, enter some session name and hit Submit.
Once you submit the session name you'll get the Manage Session screen. This is the place where all the action will take place. Come down to the Session Details section and enter a file name, say /Users/tariq/res.txt, in the Result File box. This is the file where the result of your query will get stored. If you expect your result to be very huge you can just enter /dev/null over there. Remember the result file is local to the web server. Similarly enter the error file if you wish.
Now come down to the Query box and write the query you want to execute.
Come down further to the Start Query drop down list, click on it and elect YES and hit Submit.
You should be able to see the file /Users/tariq/res.txt by now containing the result of your query. You can also view the result by clicking on View File option which will appear next to the Result File box upon the successful completion of your query.
HTH
Take a look at Hue - http://cloudera.github.io/hue/
This project is bundled with the Cloudera installation and seems to work rather well.
Best,
Sukrit

How to close program via TestComplete after failed Keword Test

So lets say I am doing a Test Complete keyword test. If something fails in it the text stops . Actually what I have founded out is that if i have 8 checkpoints if the 4th one fails the rest will always fail after it. So i get a "test execution was interrupted" error. Thats fine but it doesnt finish out the test and close the application. The reason this is an issue is because any tests after it will fail because the application is still left open. I could rewrite these tests so that the application is open when they start but is there a way to kill and application after your tests fail? If the tests pass the application is closed.
You need to organize your tests with test items. In this case, you create at least 3 test items: the first one starts the application, the second performs the test and the third closes the application. If an error occurs during execution of the second test, this second test execution is ended and TestComplete runs the third finalization test item.
Information on test items can be found in the Tests and Test Items help topic. Please note that you need to specify the Test Item value in the Stop on error column for the needed test item (the second one in the above example). Information on this and other columns can be found here. The column is hidden by default and you need to add it: right-click the header of the test items list and select Field Chooser. After this, drag the needed column to the header from the Field Chooser dialog.
Find more information on this solution in Stopping Tests on Errors and Exceptions.
Alternative solution is using the OnLogError or OnStopTest event handlers. Find description of how to handle standard TestComplete events in the Creating Event Handlers for TestComplete Events help topic.
Perhaps I'm oversimplifying, but could it be the setting for the test playback? Pls check the following page and let me know if it helps: http://support.smartbear.com/viewarticle/28751/.
If that doesn't work feel free to repost in the SmartBear Forum: http://community.smartbear.com/
The support team is monitoring the forum and I'm sure they'll be happy to help.

Resources