vendredi 26 mai 2017

React-script Fabricjs jsdom conflict,

When I start test in my project below error will happen:

FAIL src/tests/App.js ● renders without crashing

TypeError: Cannot read property 'imageSmoothingEnabled' of null

  at klass._setImageSmoothing (node_modules/fabric/dist/fabric.js:6567:38)
  at klass._initStatic (node_modules/fabric/dist/fabric.js:6348:12)
  at klass.initialize (node_modules/fabric/dist/fabric.js:8611:12)
  at new klass (node_modules/fabric/dist/fabric.js:1961:23)

Actually it happens when I create a fabricjs canvas. Is it a conflict between jsdom and fabricjs???

What is the best approach to test a HapiJS plugin, with Lab?

What is the best way to test a HapiJS plugin, for example one plugin that add routes and handlers.

Since I have to create an instance of Hapi.Server to run the plugins, should I define all the tests from the app's root, for all the plugins ?

or

should I manage to get THE instance of Hapi.Server in my plugin's local tests ?

If I go for the second option, my server will have registered all the plugins, including those that the plugin to be tested doesn't depends on.

What is the best way to approach this ?

Thanks in advance.

Test a void method with an outgoing HTTP request

I looked up some older questions here at SO and most of you say, don't test a void method.

I have a method which sends a HTTP Request to a Server and I think I still should test that even if the method is void? If not, please tell me why because many tutorials at dzone for example mention that you should test rest requests.

If I should test it, please help me to answer what I have to test and how I do that since void doesn't return anything. If you see another no go here please also tell me, I want to improve as much as I can.

Here is the Method:

private void buy(double price) {
    final String timestamp = String.valueOf(System.currentTimeMillis());
    final String amount = String.valueOf(observer.requestedAmount);
    final String ressouce = GetValuesTypes.getRessource("user").get(observer.getRelatedUser);

    String queryArgs = "wwww.doSomething.com/" + ressouce;
    String hmac512 = HMAC512.hmac512Digest(queryArgs);

    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost post = new HttpPost(GetValuesTypes.getURL());
    post.addHeader("Key", GetValuesTypes.getKey());
    post.addHeader("Sign", hmac512);
    try {
        post.setEntity(new ByteArrayEntity(queryArgs.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        System.out.println("Exception in run");
    }
    List<NameValuePair> params = new ArrayList<>();

    params.add(new BasicNameValuePair("command", "order"));
    params.add(new BasicNameValuePair("ressource", ressource));
    params.add(new BasicNameValuePair("rate", String.valueOf(rate)));
    params.add(new BasicNameValuePair("amount", amount));
    params.add(new BasicNameValuePair("timestamp", timestamp));
    try {
        post.setEntity(new UrlEncodedFormEntity(params));
        CloseableHttpResponse response = httpClient.execute(post);
        HttpEntity entity = response.getEntity();
        Scanner in = new Scanner(entity.getContent());
        String orderNumber = "";
        while (in.hasNext()) {
            orderNumber = in.nextLine();
        }
        String[] findOrderNumber = orderNumber.split(".");
        long lastOrderNumber = -1;
        try {
            lastOrderNumber = Long.valueOf(findOrderNumber[3]);
        } catch (NumberFormatException exception) {
            System.out.println("NumberFormatException");
        } finally {
            if (lastOrderNumber != -1) {
                observer.setOrderNumber(lastOrderNumber);
            }
        }
        in.close();
        EntityUtils.consume(entity);
        httpClient.close();
    } catch (IOException e) {
        System.out.println("Exception occured during process");
    }
}

How can I remove some spaces from a string? - Swift3

i have a question... i write tests for a mobile app. And at this moment i compare the prices in different currencies like pound, euro, india and so on.... A possible comparison should be "now £1.678,95". It's no problem for me to cut the "now", to cut the whitespace - short, to get the string in a possible Int or Double formation. BUT now i'am in france. In France the formation is "maintenant 2 500,00 €". No problem with the "maintenant", no problem with the whitespace outside the price and no Problem with "€".

BUT there is a space IN the price between 2 and 500. If i run my test, i have only the "2" the rest is gone! How can i do it, that the whitespace should not cut here. It should backspaced from "2 500,00" to "2500,00".

Hope you have an idea :) Thanks!

My code at this moment is :

        var firstPrice = XCUIApplication().collectionViews.cells.element(boundBy: 0).staticTexts.element(boundBy: 2).label

    firstPrice = firstPrice.replacingOccurrences(of: "£", with: "")
    firstPrice = firstPrice.replacingOccurrences(of: "€", with: "")
    firstPrice = firstPrice.replacingOccurrences(of: "₹", with: "")


    let firstPriceArray = firstPrice.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
    firstPrice = firstPriceArray[1]
    let firstPriceTrimmedDouble = firstPrice.toDouble(with: SiteIDHelper.locale(from: SiteIDHelper.SiteID(rawValue: Int(sideIDS))!))!
    print(firstPriceTrimmedDouble)

Selenium run without this error

How to run selenium without this error."[error] Element css=#lotusContainer_City > div.lotusSelect-clickable.lotusSelect-focus-border > a > #lotus-selection not found".

Nightwatch.js assert console warning

I'm really new to nightwatch and automating tests so maybe my question makes no sense for the Pro's here :)! But i thought before I continued to search the whole internet (yes i google it already) let's ask you guys if this is even possible.

I'm facing the situation to automate tests where i have to check multiple pages about localization of words in multiple languages. In the code are placeholder for words if they have to be displayed in different languages depending on some conditions. Those placeholders gets configured in an external tool and changes sometimes. Without going too deeply into detail i worked on a possible solution with our Dev's and the actual situation leads us to only one way. If there is a configuration missing in the external tool and don't display the word on our page it throws a console warning with a specific message.

Now my Question is if it's possible to check in a nightwatch test if this warning is present in the console or not and accordingly pass oder fail the testcase?

I already found a way to print out the console warning in a test but maybe there is a better way to get this test done.

And at least, no i cannot share the code because i don't have the permission to share our code :)

Already thanks for your feedback & cheers Umberto

How to generate java test validation from a swagger yaml file with swagger-codegen? [on hold]

When I generate java server stubs with swagger-codegen I get some tests without validations, only comments: "TODO: test validations".

How to generate validations from yaml? What data should I add into yaml or I need to add another config file?