How can I call desired capabilities for every test? - automated-tests

I'm new to appium and I have created set of test cases and for every test case I use #BeforeTest and add my desired capabilities
is there a way I can just call them instead of writing them for every test?
I tried to add desired capabilities into a class and call it before tests but it didn't work

Related

Is there any way to get the c# object/data on which NUnit test is failing?

I am writing unit tests for a complex application which has so many rules to be checked into a single flow by using NUnit and Playwright in .Net5. Actually the case is, to save the time for writing the test scripts for Playwright (front-end testing tool), we have used a library named Bogus to create dummy data dynamically based on the rules (because the test cases has numerous rules to be checked and it was much more difficult to write fresh data to every case). I am using Playwright script into the NUnit test and providing the data source by using [TestCaseSource("MethodName")] to provide dynamic data object for different cases.
Now, we are facing a problem that some of the tests cases get passed and some are failed and we are unable to identify that particularly which test case is causing the problem because the testcase data is being provided by the dynamic source and in that source the data is being generated by the Bogus library on the bases of the rules which we have generated. Plus, we cannot look at the tests for a long time that's why we have automated the process.
[Test]
[TestCaseSource("GetDataToSubmit")]
public async Task Test_SubmitAssignmentDynamicFlow(Assignment assignment)
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
...
});
....
private static IEnumerable<TestCaseData> GetDataToSubmit()
{
//creating data for simple job
var simpleAssignment = new DummyAssigmentGenerator()
....
.Generate();
yield return new TestCaseData(simpleAssignment);
....
Now, my question is, is there any way so that we can view that what were the actual values in the object in the failed case, when we see the whole report of the testcases? So that we can come to know that which certain values are causing problems and eventually fixed those.
Two approaches...
Assuming that DummyAssignmentGenerator is your own class, override its ToString() method to display whatever you would like to see. That string will become part of the name of the test case generated, like...
Test_SubmitAssignmentDynamicFlow(YOUR_STRING)
Apply a name to each TestCaseData item you yield using the SetName() fluent method. In that case, you are supplying the full display name of the test case, not just the part in parentheses. Use {m}(YOUR_STRING) in order to have it appear the same as in the first approach.
If you can use it, the first approach is clearly the simpler of the two.

Scalamock expect eventually

I'm using scalamock to write a test. The problem is that action is asynchronous.
I have the following pseudo code
val resultCollectorMock = mock[ResultCollector]
(resultCollectorMock.collectResult _).expect(someResult)
val serviceUnderTest = new ServiceUnderTest(resultColletorMock)
serviceUnderTest.runAsyncJob(someParams)
This fails because the result is computed asynchronously, at time when the test ends, it's still not ready, so collectResult wasn't called, yet.
What I want to have is expectEventually(value)(patienceConfig) that is able to wait for some time for the method to be called.
I tried to use a sutb and verify instead, I wrapped it in eventually from scalatest but to no avail. For whatever reason verify seems to break the test at first evaluation.
you should use AsyncMockFactory with an appropriate test suite and Futures as described in the docs at https://scalamock.org/user-guide/integration/

if-else conditions based on expect statement results

I'm working towards testrail integrations, i want to update testrail after each test pass/fail. Lets day if i've a test like below
it('rightpanel should exist', () => {
//some logic or preparatory work
expect(rightpanel.isLoaded()).to.be.true;
// here i want to know whether above expect statement failed or passed.
// based on it, i want to update test rail by making a webservice call
});
we are using WDIO, is there a better way to integrate to testrail? No one replies on their community forum so, i'm asking here.
With mocha you can use a repoter to manage the results of your tests.
The default reporter is Spec, but if you use json-stream you can attach another process to this stream to send test reports to testrail while executing.
Otherwise, if you don't need to send them in real time, you can use the json reporter and parse them in a single call.
You can also check on github some existing reporter that connects directly to testrail:
https://github.com/CommodoreBeard/mocha-testrail-advanced-reporter
https://github.com/awaragi/mocha-testrail-reporter
complete list

How to mock an inlined InitiatingFlow return value during another flow

I have SomeBigFlow that calls multiple subflows inside it i.e ValidateFlowA, ValidateFlowB. Assuming it is mandatory for A and B to be initiating flows not functions.
How do I mock a return value for ValidateFlowA when I run the SomeBigFlow in Junit?
I've seen some references to using registerAnswer to mock flows' return value here. I am also curious why this function is only available for InternalMockNetwork.MockNode but not MockNetwork.StartedMockNode which is typically used during junit testing)
I thought I could replicate it by having node[1].registerAnswer(ValidateFlowA.class, 20). But when I ran node[1].startFlow(SomeBigFlow).resultFuture.getOrThrow(), the ValidateFlowA is still using its default call implementation instead of returning the mocked 20 integer value. Maybe I'm using it wrong.
Any pointers on how to make this work or is there a solution to achieve mocking inlined subflows returned values? The only other way I can think of is have a rule of thumb that whenever calling an inlined subflow, put them in an open fun that can be overridden during mocknetwork testing - this makes inlined subflow tedious, hoping for a neater way.
For now, you'd have to use a similar approach to the one outlined here: Corda with mockito_kotlin for unit test.
In summary:
Make the FlowLogic class you are testing open, and move the call to the subflow into an open method
For testing, create a subclass of the open FlowLogic class where you override the open method to return a dummy result
Use this subclass in testing

Spying on a method parameters in phpunit, while calling the original method

I am trying to understand is it possible with phpunit to create spy on a method, while calling the original method.
I have done it in java, but I don't see a way to do it in phpunit. I only find that if I spy on the invocations of the method, I also need to mock it.
Example code:
$this->spy = $this->getMockBuilder('\ClassUnderTest')
->setMethods(['methodToSpy'])
->getMock();
$this->spy->expects($this->any())
->method('methodToSpy')
->will($this->returnCallback(array($this, 'stubMethodToSpy')));
So in the test, I want to "spy" on the call to the real method 'methodToSpy()', so I can make on-the-fly analysis on the parameters passed to it (I need to use them in the test later on).
Any idea if this is possible? (or maybe it is not possible in phpunit because it is not multithreaded like java)
You are looking for test proxies.

Resources