I want to simulate revert-error, launching tests of Solidity contract with Truffle, but I need to get input call data for simulating it in other project, which I got from debugger. How can I launch debug despite errors?
You can use revertedWith to simulate revert-error, in my case I revert if the user don't have enough tokens.
it("Transfer token", async ()=> {
await expect(instance.transfer.call(accounts[1],9999999999)).to.be.revertedWith("You dont have enough tokens")
});
Related
Whenever I'm running the app in Xcode, I'm running into this issue and I can't really figure out what to do. I'm just trying to fetch all the items in an entity in Core Data, returning a Job array. The only thing I can do if this happens is stop the the app, close it, and open it in the emulator without clicking on the run button.
Here's the image of the code and the error I'm talking about:
Is there anything I can do to fix this? Is this a debug issue or is it a real app problem?
You would use something like this
func generateData(context: NSManagedObjectContext) async throws {
try await context.perform {
//Your fetch code here
}
}
Here is a WWDC video on the subject https://developer.apple.com/wwdc21/10017
The biggest thing I think is not chaining these calls try an condense them, I recently had a client that that was calling perform inside other performs.
async await is all about straight lines you should know exactly what is happening, when it is happening and in what order. There is no hanging on to anything.
I am using Protractor to run tests on a login-based web application on CI with around 1000 tests running daily. It was all going well until all my tests started to fail. The reason is that the web-based app depends upon login, and due to a minor issue with the app, login failed, followed by that all my tests failed and it took 8hrs to complete! This was a big mess. I started to wonder how can I avoid such failures. I found Protractor's fail-fast mode but it did no good because it would stop execution on the first failure. I want something that stops the execution as soon as login fails but runs all the tests (irrespective of any failure) if login passes. Is there a way to work this out?
Tests are run in docker in headless mode.
These two guys are your friends: await browser.close(); & await process.exit(1);
Never really thoughts about it, but seems like I'll need to implement this too in my login method
async login(username, password, quitOnFailure = true) {
// do what you normally do to login
await sendKeys(this.$usernameInput, username);
await sendKeys(this.$passwordInput, password);
await this.$submitButton.click();
await this.waitForLoad();
// lets says if for testing purposes you need to continue on failure
// and check certain scenarios make this optional
if (quitOnFailure) {
// in my case if I'm not logged in I get a red label displayed
if (await this.$errorLabel.isPresent()) {
await browser.close();
await process.exit(1);
}
// this may be your way for checking if you're not logged in
// try to wait until a welcome message is present, if not, quit
try {
await browser.wait(
ExpectedConditions.presenceOf(homePage.$welcomeMessage),
10000,
`Failed at ${__file} -> ${__function}() -> line ${__line}`
)
} catch (e) {
console.log(e);
await browser.close();
await process.exit(1);
}
}
};
``'
I handle this in my CI environment by adding a BVT step. I use jenkins to do so, I cerated a Pipeline in Which before starting the entire Test suite, I just run BVT Job, in which I just run Login test. If BVT is pass next step is to Run full test suite, but if BVT is failed next step will not even execute.
I want onPrepare to finish before any tests are run and I'm using async / await.
I'm new to javascript and protractor but I've been writing test automation for a couple of decades. This seems like an incredibly simple thing to want to do, have onPrepare finish before a test starts, but I'm confused my everything I've seen out there.
I've set SELENIUM_PROMISE_MANAGER: false so I don't want to use promises to do this, right?
My landing page in anguler
do I use async and await on onPrepare or browser.driver.wait or webdriver.until.elementLocated? If so, do I put 'await' before those waits? (That seems redundant)
onPrepare: async() => {
await browser.driver.get( 'https://localhost:8443/support-tool/#/service/config');
await browser.driver.findElements(by.className('mat-table'));
browser.driver.wait(webdriver.until.elementLocated(by.css('mat-select-value')), 10000);//(Returns webdriver not defined)
},
first, I get webdriver not defined when I run it. Once I get it to work, will my tests wait for onPrepare to be completed before they start running?
So Protractor is a wrapper for the webdriverJS and webdriverJS is completely asynchronous. To give a very high level definition, Protractor wraps webdriverJS up so that every action returns a promise (for instance .get(), .sendKeys(), .findElement()).
Previously webdriverJS had what is referred to as the 'control flow' which allowed users to write code as they would in any synchronous programming language and the fact the almost everything is a promise was handled behind the scenes. This feature has been deprecated in the latest versions and the main reason is that the introduction of the async/await style of handling promises makes it much easier for users to manage promises ourselves.
If you are using protractor 6.0+ the control flow is disabled by default but it will be disabled for you regardless as you have you have set SELENIUM_PROMISE_MANAGER: false. You will need to manually manage your promises, which you are doing, by using async/await.
browser.driver vs browser
I also want to point out the by using browser.driver.get you are referring to the underlying selenium instance and not the protractor wrapper instance therefore it will not wait for the angular page to stabilize before interacting (I could be mistaken on this). There is more info on the distinction in this thread.
Any action that involves the browser or the file system will likely be a promise so include the await before them and any function that contains an await needs to be declared async.
I would write your code as follows:
onPrepare: async() => {
await browser.get('https://localhost:8443/support-tool/#/service/config');
let someElement = await element(by.css('mat-select-value'));
await browser.wait(protractor.ExpectedConditions.presenceOf(someElement), 10000);
},
Finally, as long is your onPrepare is using awaits properly it should for sure complete before your tests begin.
Hope that helps and is clear, it was longer than I anticipated.
I'm using Cypress for end-to-end testing. In my beforeEach, I'm using an SDK I've been provided to seed data on a server (the SDK sends API calls to the server but does not use cy.request inside it). The method on the SDK returns a promise, therefore I figured I could return the promise like so:
beforeEach(() => {
return sdk.createProperty(...);
});
My test then does something like this:
it('displays a property', () => {
cy.visit(`/companies/${appTestData.companyId}/properties`);
...the rest is commented out currently...
}
This actually works as intended, that is, it waits until the server response is returned before running the tests, but I see the following warning in the console when the test actually runs:
Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise...
I noticed if I change my beforeEach to use cy.then, the warning goes away:
beforeEach(() => {
cy.then(() => sdk.createProperty(...));
});
It seems a bit unnecessary and was kind of a stab in the dark, so I'd like to know if there's a prescribed way of doing what I need to do. I can't change the SDK I'm using to use cy.request, which I assume would also prevent the warning. Thanks.
Probably not what you want to hear, but can I confirm you that using cy.then(...) is the most standard way of waiting for a Promise in Cypress I know of.
After reading your question, I have tried to use Cypress Network Requests features to wait for a fetch('my/url') in a before(), but it doesn't seem to be detecting the request at all.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,async () =>
{
await MainPage.bmpsource.SetBitmapAsync(bmp);
});
I putted codes in while loop .When I click button or some controls on running app,the app will crash and pinpoint on code "await MainPage.bmpsource.SetBitmapAsync(bmp);".
VS output:
there will be an exception of type 'System.Threading.Tasks.TaskCanceledException' occurred in System.Private.CoreLib.ni.dll but was not handled in user code
A task was canceled.
Maybe someone can help me,thank you!
You should not use CoreDispatcherPriority.High as that can cause issues (and may be causing this issue).
Please check the link above for more information on this matter.