jeudi 27 août 2020

Firebase Test Lab UI Testing for WebView app (React)

Speaking of an app built with React to serve both mobile platforms (iOS and Android) is there any way to use the Firebase Test Lab to do specific clicks or some sort of user flow like in Selenium?

Unfortunately the robo script recording in Android Studio only works for native Android UI apps but is not able to record any clicks done in a webview which is very unfortunate as that is exactly what I need.

Firebase is great since it allows me to test on a variety of devices but the bot in the robo test can't even get behind the welcome screen of the React app.

I don't necessarily wanna stick to Firebase. If there's another solution that let's me record a user workflow and test that on multiple devices I'd be glad to hear about it!

Is there a way to handle a popup for newsletter in selenium(java)

I am trying to test a login functionality of an website.. the problem arises when a pop up window for signing up for a newsletter pops up. I want to cancel and also i want to enter a valid email/invalid email and submit the popup window. please help attaching a screenshot of the same enter image description here

Can I run TestCafe tests with unused Typescript page objects

I'm writing tests in TestCafe using Page Objects pattern.

Some of the page objects are written beforehand (before they are actually used), since I know the page and know what to expect.

But, when trying to run tests with unused page objects I will get an error message like:

Error: TypeScript compilation failed.
C:/path-to/a.page-object.ts (40, 7): 'PageObjectExample' is declared but never used.

Is there a TestCafe or TypeScript option to (temporarily) allow for the compilation of these kinds of tests?

How can I Test Output of a File using Mocha

I am currently writing a short piece of code for a Zapier integration. The code simply takes an input (provided by Zapier), and generates an output.

I am developing this locally because it is quicker and faster, but I also want to add tests to check that an input produces the right output.

I need to figure out how to require the file into the Mocha test, and then check the output is what it should be:

//index.js

// This is mock data which will be inputted automatically by Zapier
const inputData = {
  "data": "My String",
}
// ALL ABOVE THIS LINE IS REMOVED WHEN I COPY OVER TO ZAPIER



let output = {};

let newData = inputData.data;
newData = newData.toLowerCase();
output = {...output, newData};

console.log(output);
// test.js

const assert = require('assert');
const indexFile = require('../index');

describe('Output', () => {
  it('should return', () => {
     // todo test that string was converted to lower case correctly
  })
})

The only thing I can think of, is wrapping the whole file in a function, and adding a return statement, which may be the only way..?

Math.floor not working for cartian test case

I am doing a coding challenge that requires me to find the rounded down average of integer array elements. The challenge has 3 test cases, 2 of which pass, except for the last one which does not and i have no idea why. This is my code:

function getAverage(marks){
  //TODO : calculate the downwar rounded average of the marks array
   return Math.floor(marks.reduce((acc, cur) => {
    return acc + cur;
  })) / marks.length;
  
}

And these are the test cases:

Test.assertEquals(getAverage([2,2,2,2]),2);
Test.assertEquals(getAverage([1,2,3,4,5,]),3);
Test.assertEquals(getAverage([1,1,1,1,1,1,1,2]),1);

The last test case returns 1.125 instead of 1, even though I am rounding down the result. What could be the reason for this?

How to update dynamic date on body for post params within JVM PACT contract?

I have a POST request that takes date as a param from within my contract file for a PACT test.

return builder
    .uponReceiving("A request to create a Zoom meeting")
    .path(createMeeting)
    .method("POST")
    .headers(headers)
    .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}")
    .willRespondWith()
    .body(body)
    .toPact();

But I'd like this to be dynamic, having perhaps today's or tomorrow's date, otherwise it would have an expired date. Could you please advise on how to do do this and if possible to keep it from the consumer side.

These are both Consumer and Provider samples for my request.

Consumer

@ExtendWith(PactConsumerTestExt.class)
public class PACTConsumerEdUiVcTest {

Map<String, String> headers = new HashMap<>();

String createMeeting = "/manage/create-meeting";

@Pact(provider = VC, consumer = ED_UI)
public RequestResponsePact createPact(PactDslWithProvider builder) {

    headers.put("Content-Type", "application/json");

    DslPart body = new PactDslJsonBody()
            .date("start_time", "yyyy-MM-dd'T'HH:mm:ss.000'Z'", new Date());


    return builder
            .uponReceiving("A request to create a Zoom meeting")
            .path(createMeeting)
            .method("POST")
            .headers(headers)
            .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}")
            .willRespondWith()
            .body(body)
            .toPact();
}

@Test
@PactTestFor(providerName = VC, port = "8080")
public void runTest() {

    //Mock url
    RestAssured.baseURI = "http://localhost:8080";

    Response response = RestAssured //todo: dynamic start time that won't expire. 27/08/2020
            .given()
            .headers(headers)
            .when()
            .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}")
            .post(createMeeting);

    assert (response.getStatusCode() == 200);
}

}

Provider

@Provider(VC)
@PactFolder("target/pacts")

public class PactProviderEdUiVcTest {

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactTestTemplate(PactVerificationContext context, HttpRequest request) {
    request.addHeader("Authorization", AUTHORIZATION_TOKEN);
    context.verifyInteraction();
}

@BeforeEach
void before(PactVerificationContext context) {
    context.setTarget(new HttpsTestTarget(BASE_PACT_VC_URL, 443, "/"));

    getAuthorizationToken(UserType.TEACHER);
}

@State("A request to create a Zoom meeting")
public void sampleState() {
}

}

Many thanks.

Can not execute controller test with @SpringBootTest

I have a Spring Boot application. Version is 2.3.1.

Main Application looks like:

@AllArgsConstructor
@SpringBootApplication
public class LocalServiceApplication implements CommandLineRunner {
    private final DataService dataService;
    private final QrReaderServer qrReaderServer;
    private final MonitoringService monitoringService;

    @Override
    public void run(String... args) {
        dataService.fetchData();
        monitoringService.launchMonitoring();
        qrReaderServer.launchServer();
    }

    public static void main(String[] args) {
        SpringApplication.run(LocalServiceApplication.class, args);
    }
}

After the application is started I have to execute 3 distinct steps which have done with CommandLineRunner:

  • first gets remote data and store it locally (for test profile this step is skipped)
  • start async folder monitoring for file uploads with WatchService.
  • launch TCP server

I have a controller like:

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/v1/permissions")
public class CarParkController {
    private final PermissionService permissionService;

    @PostMapping
    public CarParkPermission createPermission(@RequestBody @Valid CarParkPermission permission) {
        return permissionService.createPermission(permission);
    }
}

Ant test with Junit 5 looks like:

@ActiveProfiles("test")
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class CarParkControllerIntegrationTest {
    @Autowired
    private MockMvc mockMvc;
    @MockBean
    private PermissionService permissionService;
    private final Gson gson = new Gson();

    @Test
    void testCreatingNewPermissionSuccess() throws Exception {
        CarParkPermission permission = CarParkPermission.builder()
                .id(56)
                .permissionCode("1234")
                .build();

        when(permissionService.createPermission(refEq(permission))).thenReturn(permission);

        postPermission(permission).andExpect(status().isOk());
    }

    private <T> ResultActions postPermission(T instance) throws Exception {
        return this.mockMvc.perform(post("/v1/permissions")
                .contentType(MediaType.APPLICATION_JSON)
                .content(gson.toJson(instance)));
    }
}

Looks like it should work fine.

However, the test isn't executed:

2020-08-27 14:42:30.308  INFO 21800 --- [           main] c.s.i.CarParkControllerIntegrationTest   : Started CarParkControllerIntegrationTest in 8.593 seconds (JVM running for 10.03)
2020-08-27 14:42:30.334  INFO 21800 --- [           main] c.s.s.s.DataServiceTestImpl     : Fetch data for test profile is skipped
2020-08-27 14:42:30.336 DEBUG 21800 --- [   carpark-ex-1] c.s.monitoring.MonitoringServiceImpl     : START_MONITORING Results from Cameras for folder: D:\results-from-camera
2020-08-27 14:42:30.751 DEBUG 21800 --- [           main] c.s.netty.TCPServer              : TCP Server is STARTED : port 9090

After such lines execution hangs up forever.

How to solve this issue?