问题
I'm trying to run a simple test scenario on sauce-labs, but the issue is that sauce-labs doesn't identify the test-status as passed or failed on its own. I've gone through multiple solutions but couldn't make any of them work.
I would love to know if we can do something in the feature file rather than doing something externally if possible. Following are my feature and java files.
Feature File
Java File
Any help will be appreciated. I'm a JAVA newbie & just starting on the Karate Framework and do not have in-depth knowledge of how things are working.
回答1:
The Remote Driver is just sending along requests for actions and requests for information. What that information is "supposed" to be is decided by the assertions in your test. Sauce Labs has no way of knowing what that is without your input.
There are 2 ways to tell Sauce Labs the status of the test.
The recommended way is to use the API: https://wiki.saucelabs.com/display/DOCS/Job+Methods#JobMethods-UpdateJob You just need your sauce username, access key and the job ID (job ID is the same as the driver's session ID).
The less reliable, but easier to implement way is with a custom JavaScript command: https://wiki.saucelabs.com/display/DOCS/Annotating+Tests+with+Selenium%27s+JavaScript+Executor "sauce:job-result=passed"
Either of these can be put into an AfterClass or TestWatcher methods.
来源:https://stackoverflow.com/questions/63264238/how-to-set-sauce-labs-job-result-as-pass-or-fail-using-karate