I have just installed the mocha-sidebar extension in vs code. I am using the following config in my settings.json file:
{
"mocha.files.glob": "test/**/*.spec.js",
"mocha.requires": [],
"mocha.env": {
"NODE_ENV": "test"
},
"mocha.sideBarOptions": {
"lens": true,
"decoration": true,
"autoUpdateTime": 1000,
"showDebugTestStatus": true
}
}
If I click the green play button in the extension window it runs the tests correctly and shows the results in the sidebar. If I now update the test to make it fail the previously green circle next to the test changes to yellow, but nothing else happens.
I would expect the test to be shown with a red circle (failing), I would also expect the test in the test file to have a red dot next to the failing test, but this remains green.
I have to run the tests by pressing the green play button again from the sidebar.
The other thing I have noticed is that when a test fails, it reports the failure in the test file e.g. //expected a to equal a. But when the test is updated to pass the comment does not get removed and I have to switch files and then return to the test file which then seems to remove the comment.
Thanks in advance!
Related
I’m adding a couple of animations to an app that has Percy taking snapshots in the cypress tests.
I’m trying to figure out a way to wait for the animations to finish before taking the snapshot.
I’m aware that cypress already does that by default according to the docs. But it seems that it only waits until the element is safe for an ACTION, but not regular assertions.
Let’s use my logo animation for example. It slides from the left to center. The flaky tests capture the snapshot anywhere in its path.
Now, just for a test, I asked cypress to click the logo and then Percy works alright, the snapshot is only taken at the end of the animation.
For this case it’s ok, since my logo does not have an action related to it. But what if clicking it had a redirect, for example?
How can I tell cypress to wait without using an action?
Can you assert the slide has finished before the snapshot?
It would involve a element.getBoundingClientRect() and manually checking the position.
it('waits for logo to slide to center',
{viewportWidth: 1000}, // ensure fixed, appropriate viewport for the test
() => {
cy.get('#myLogo')
.should($logo => { // using should will retry until animation finishes
const left = $logo[0].getBoundingClientRect().left
expect(left).to.eq(450)
})
// snapshot now
}
)
I'm doing this with a drag and drop scenario, but finding the numbers have rounding errors.
I've added chai-almost to sort it out.
const chaiAlmost = require('chai-almost')
chai.use(chaiAlmost(1)) // allowed amount of variance in equality is 1
...
expect(left).to.almost.eq(450)
Simplest way is to add a hard cy.wait(animation-time-in-ms) before the snapshot.
It won't make the difference to the test runtime since you need the animation to finish before the test can complete.
I am using VSCode and the (default) Light+ theme, on Windows 10. I like this theme but have a lot of trouble seeing the yellow against the white - same is true for all the "light" themes, so there is no point changing themes.
I have found workbench.colorCustomizations in Settings - specifically changing editorBracketHighlight.foreground1 , but it won't stay on the colour I have selected (dark blue) - it sometimes shows as blue (and not consistently) when I bring up the VSCode editor, but, even if I see blue initially, it switches back to yellow shortly after. There seem to be various ways to change the settings, but I haven't found one that will stay!
BTW I have specified editor.bracketPairColorization.enabled (and this does work, using the old colours), so this is not the problem...
Help would be appreciated! TIA
PS I don't care whether this is associated with my workbench or all projects, and all languages or each language specifically (I am just doing Go right now), as I would want this for all projects, and all languages...
To get a better idea of whats going on behind the scenes, first install the Scope Inspector
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#scope-inspector
then open your settings.json with ctrl+shift+P -> "Preferences: Open Settings.json".
Now open a .go file that you want to use as a test subject... and then enable the scope inspector:
ctrl+shift+p -> Developer: Inspect Editor Tokens & Scopes
For me I am using a Slice tutorial as example, Light+ on MacOS :
moving around your cursor you will see different scopes are applied to different tokens in your code.
In this example the inspector shows that it has 2 scopes being applied.
To change the color, go to the Settings.json file...
Inside, alongside whatever else you may have added, put in the "editor.tokenColorCustomizations" object with a sub "textMateRules" object, and include the scopes you want to target using the ScopeInspector mentioned above:
{
"editor.tokenColorCustomizations":{
// "comments": "#33FFCC", //will affect all comments in VSCode...
"textMateRules": [
{ "scope": "punctuation.definition.bracket.square.go",
"settings": {
"foreground": "#8110239f",
"fontStyle": "bold",
}
},
//.... Other rules you may add for different scopes you find with inspector etc...
]
} //end "editor.tokenColorCustomizations"
}
In this example, The result immediately changes to a dark red:
It seems that I can now colour the brackets as desired without using testMateRules, as follows:
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"bracket-pair-colorizer-2.forceUniqueOpeningColor": false,
"bracket-pair-colorizer-2.showVerticalScopeLine": true,
"bracket-pair-colorizer-2.showHorizontalScopeLine": true,
"bracket-pair-colorizer-2.colors": [
"#3344F0",
"Orchid",
"LightSkyBlue",
"Green"
],
This seems to work - maybe someone could let me know if there is a problem with this! Thanks
I have a pop up window containing a script in its head. And this script should be triggered by click on the window button. But after click on this button the script does not run. Could you suggest the reason?
Steps to reproduce:
Click on a button in the main window.
Child window containing a simple form is open.
Move to the child window, fill in the form fields and click on submit button.
Expected result: The click triggers a script located in the child window head. The script process the form and submit it.
Actual result: an error arises: "submitMyForm is not defined" (reference: submitMyForm() is a method containing in the script mentioned above).
So the problem is that the child window form fields can be populated and form button can be clicked but the script bounded to the button by means of the link <a href="javascript:submitMyForm();"> does not work as the function submitMyForm() is not found. Obviously the reason of the test failure is stubbing the child window which is performed to prevent having 2 windows at the same time. After this the child window is opening in the same browser tab as Cypress is not able to work with 2 windows open in the same time. But in this case the script stops working neither from the test nor by performing the click manually.
Here is a code snippet from the Cypress test:
const pop_url = `/dir1/dir2/file.php?id=${sectionId}`; // Here is a new window URL
cy.window().then( win => {
const stub = cy.stub(win, 'open').as('windowopen');
newSurveySectionListObj.AddNewBtnClick(); // Triggers form opening in the new window
cy.get('#windowopen').should('be.called.with', pop_url);
cy.window().then( $win => {
$win.location.href = pop_url
newSurveySectionListObj.typeDropdownSelect('Matrix'); // works fine
newSurveySectionListObj.modalDescriptionFldType('Cypress test string'); // works fine
newSurveySectionListObj.responseTypeDropdownSelect('Checkbox'); // works fine
cy.get('a[href="javascript:submitMyForm();"]').click(); // Does not work despite the button is clicked. An error "submitMyForm is // not defined" arises
});
});
You are going beyond what Cypress is capable of/designed for.
I would question why you are using a separate window in your app? You will run afoul of pop-up blockers that will prevent the new window being opened anyway. A percentage of users won't be able to work it out.
There are 2 approaches to this:
Use a modal dialog to achieve this (not great on mobile)
Use another route/page to display your form, return to the prev page when done
These have the advantage that they won't break with pop-up blockers, and your Cypress tests will work, as they are still in the same window.
As seen here, It shows green arrow, but test has failed.I need to click on the test to see result:
Without clicking on test, it seems as if test has passed:
I want the test to be shown in red color or red arrow mark
You can use cy.should. Now when assert fail, test will fail
cy.should(() => {
expect(result).to.equal(true)
});
I have a test that looks like the following:
func testNextButtonDisabled() {
let app = XCUIApplication()
XCTAssertFalse(app.buttons["Next"].enabled)
}
This test fails because, in addition to my own "Next" button that I've created, the keyboard return button is labeled 'Next'. This test fails with the error:
UI Testing Failure - Multiple matches found
How can I differentiate between my own 'Next' button and the keyboard 'Next' button?
The specific solution to this problem is to look for elements that are descendants of the main window.
func testNextButtonDisabled() {
let app = XCUIApplication()
XCTAssertFalse(app.childrenMatchingType(.Window).elementBoundByIndex(0).buttons["Next"].enabled)
}
For a general solution to solve problems like this: In Xcode run the "Record UI Test" again to see how Xcode thinks you should be referencing the element in which you're interested.