Cypress - web pages are loading slower than on a browser - cypress

I started using Cypress recently and i noticed that running a test could take 60-80 seconds, but if i go through the same UI "flow" on my browser, it takes 20-30 seconds for me to complete.
Is this normal?
Are there any configurations that are affecting it?
My test is only a few lines long, using only cy.get() and cy.contains().

I have found that one of the causes of slowness of Cypress tests in the GUI is the list of actions unfolding in the Cypress left sidebar.
You will notice that just below the title of each test is the word "⯆ Test" with an arrowhead to its left and below it, all the actions get added as they happen. If you close that list by clicking on the word "Test" the list closes and the tests now run much faster. Now even if you close one, the next test will once more have it open.
To make the default state be closed you need a little hack in the code.
As I have written elsewhere:
In the file Cypress\resources\app\packages\runner\dist\cypress_runner.js look for var Hook = Object in the code. A little below that (line 102918 in version 3.8.3, line 156012 in version 4.5.0) change the isOpen field value from true to false.
Your tests should now run without any slowdown.
Update for versions 6 and up:
In the same file as above, look for the string: this.state === 'failed' and change the line from:
return Boolean(this.state === 'failed' || this.isLongRunning || this.isActive && (this.hasMultipleAttempts || this.isOpenWhenActive) || this.store.hasSingleTest);
to:
return Boolean(this.state === 'failed' /* || this.isLongRunning || this.isActive && (this.hasMultipleAttempts || this.isOpenWhenActive) || this.store.hasSingleTest */);

Cypress test are much slower than unit test and that's normal. The difference between UI and headless run may caused by cypress initialising between command and test.
To reduce time needed to pass test avoid cy.wait(, instead use e.g. cy.get( instead.
Also you can try how long takes to run with --headless --browser chrome flags.

Cypress has to run a proxy on 3rd party browsers so that they can record the requests being sent and received. This can slow down load times considerably.
The solution I used was to run my tests in their provided electron browser. e.g.
cypress run -s [your spec file] --headed -b electron
--headed - Shows the electron window so you can know what's happening
-b electron - Use the electron browser

Related

How to Run List of random multiple test cases in Cypress and how to make command string shorten

Lets say i have 300 test cases and among them 100 are failing now i want to run those 100 test cases again (Note: i have even rerun the cypress test cases with appropriate option and it even run the test cases for finding flaky test cases)
Now i have a list of failing 100 test cases in a notepad or Excel sheet now
is there any mechanism to run this test cases in CYPRESS
if i go with
cypress run --spec=cypress/integration/one.sepc.ts,cypress/integration/two.spec.ts"
that 100 test cases will cause a big string and it looks like
cypress run --spec=cypress/integration/one.sepc.ts,cypress/integration/two.spec.ts, ..... hundread.spec.ts"
this will leave that command is a huge text and complex to maintain so is there any way to run the list of failing test cases only at whatever time I want to run after fixing the application code or data
any suggestions will be helpful
More info
I was looking for the way it runs multiple test cases mentioned in one text file reference or dictionary reference
For Example, if I run all 100 test cases and 20 among them failed so I would maintain the file names and paths which are failing in the file or dictionary
and now I want cypress to take this file and run all the test cases references which are failing thereby running those specific test cases which are failing
(Note: i am aware of retrys to be placed for the execution
npx cypress run --spec "cypress/e2e/folderName" in cmd run all the specs in cypress folder.
describe.only("2nd describe", () => { it("Should check xx",() =>{ }); it("Should check yy", () => { }); }); it can only run the specific suit. Run specific test case use it.only("Should check yy", () => { });

Cypress open not refreshing session for each describe

I have Cypress 9.0.0 installed, noticed 2 issues with cypress open
Issues 1: When we have multiple describe, recent days after Cypress9.0 upgrade , session is not loaded properly for second describe , it just retains first describe screen
Issue2: When I try to close Cypress running (execution window) , its not closing it. I need to "STOP" in other Cy window
Issues 1:
I have 2 describe
Describe(1)
{
before{
loadsite&login(user1)
}
it(test1)
it(test2)
}
describe (2)
{
before{
loadsite&login(user2)
}
}
When I execute above test with cypress Open , describe(1) is executed successfully m but describe 2 is not refreshing execution window , its still in describe 1(it(test 2) screen)
I tried to install fresh , still noticing same issue , so every time I need to give only, or skip describe , Really appreciate solution for this

test continues to run in cypress runner after it fails, does not timeout

enter image description here
I have the following test in cypress:
cy.visit('/main.html')
cy.get('#homeTitle').contains('Welcome')
this passes.
If I change the contains value to "Welcome2" test should fail, and it fails in the runner, but the timer displayed continues to run, and it will not proceed to next test.
Seems like it doesn't time out or something.
Are you trying to test that the element with id #homeTitle should contain the text message 'welcome' ? If so try this:
cy.get('#homeTitle').should('contain','welcome');
I don't quite understand your issue, but I will look harder.

Testing a long process in Xamarin Test Cloud

I have a question about Xamarin Test Cloud, hope someone can point me in the right direction.
When a user taps a button in my app, a process runs for around 30 minutes. I added a Unit Test project and it runs perfectly in the emulator.
However, I need to test it in real devices, so I decided to use Xamarin Test Cloud. When I run the test there, it doesn't complete it. As I said, it should take 30 minutes but the test finishes almost immediately.
Here is the code of my Test:
[Test]
[Timeout(Int32.MaxValue)]
public async void Optimize()
{
await Task.Run(async() =>
{
app.Screenshot("Start " + DateTime.Now);
app.Tap(x => x.Marked("btnOptimize"));
await Task.Delay(120000);
app.Screenshot("End " + DateTime.Now);
}
}
If I run the test in the emulator, the screenshot names are (for instance) "Start 12:00:00" and "End 12:30:00" respectively (so it means that it runs for 30 minutes, as expected). However, in Test Cloud I get (for instance) "Start 12:00:00" and "End 12:02:00", which means that the test runs for only 2 minutes. But that's because I added the delay. Without the delay, it will run for only 5 seconds.
Is that what I need? I can add 1800000 so the test can be completed in 30 minutes, but what if I don't know the time?
Thank you and sorry if it's a basic question
Something like this should do the job:
[Test]
public async void Optimize()
{
app.Screenshot("Start");
app.Tap("btnOptimize");
app.WaitForElement ("otherButton", "Timed out waiting for Button", new TimeSpan(0,30,0));
app.Screenshot("End");
}
Where "otherButton" becomes visible when the task is done. There are other Wait methods available in the API.
But, note that the Xamarin Test Cloud has a thirty minute maximum per test by default. That default can be modified by contacting Xamarin Test Cloud support.
Also, it is not a good practice to include non-deterministic information or any information that may vary per device or run in your screen shot titles. When you run on more than one device the test report steps and screenshots are collated partially by the screen shot titles so they should match across devices for best results.
While I have never tried a timeout length of 30 minutes, the Calabash allows you to wait for a condition using wait_for):
The following snippet is an example of how to use wait_for to detect the presence of a button on the screen:
wait_for(timeout: 60, timeout_message: "Could not find 'Sign in' button") do
element_exists("button marked:'Sign in'")
end
Ref: https://docs.xamarin.com/guides/testcloud/calabash/working-with/timeouts/
Just an FYI: 30 minutes is a really long time for a mobile device to be "background processing" without user interface interaction, if you are targeting iOS/Apple Store, this death sentence in getting Apple submission approval as they will never wait that long for an app to process something....
You need to identify tap by Id and add WaitForElement(first argument is query you want to wait on) in correct syntax like given below. It should work for you.
app.Screenshot("Start " + DateTime.Now);
app.WaitForElement(x => x.Id("btnOptimize"),"Optimization timed out",new System.TimeSpan(0,30,0),null,null);
app.Tap(x => x.Id("btnOptimize"));
app.Screenshot("End " + DateTime.Now);

Ruby/Selenium WebDriver - Pausing test and waiting for user input, i.e. user inputs captcha

I'm using the Selenium WebDriver and Ruby to perform some automation and I ran into a problem of a captcha around step 3 of a 5 step process.
I'm throwing all the automation in a rake script so I'm wondering is there a command to pause or break the script running temporarily until I enter data into the captcha and then continue running on the next page.
To build on seleniumnewbie's answer and assuming that you have access to the console the script is running on:
print "Enter Captcha"
captchaTxt = gets.chomp
yourCaptchaInputWebdriverElement.send_keys captchaTxt
If you just want to pause and enter the captcha in your browser, you can just have it prompt at the console to do that very thing and it'll just sit there.
print "Enter the captcha in your browser"
gets
You could also set the implicit wait to decently long period of time so that Selenium would automatically see the next page and move out. However, this would leave the important Captcha step (for documenting / processes sake) out of your test unless you're pretty anal with your commenting.
Since this is an actively participating test requiring user input I would say that making the tester press "enter" on the console is the way to go.
Since you are writing the test in a script, all you need to do is add a sleep in your test i.e. 'sleep 100' for example.
However, it is bad to add arbitrary sleeps in tests. You can also do something like "Wait for title 'foo'" where 'foo' is the title of the page in Step 4. It need not be title, it can be anything, but you get the idea. Wait for something semantic which indicates that step 3 is done and step 4 is ready to start.
This way, its more targeted wait.
This has been implemented in JAVA, but similar technique.Your solution could be found here

Resources