how to test if a string DON'T match using protractor - protractor

I'm migrating my karma-ng-scenario tests suite to protractor. I would like to do something like
// karma-ng-scenario
expect(element('legend').text()).not().toBe("LOGIN_CONNECT");
in the protractor way. But it seems there isn't a not() function.
I'm using angular-translate to bind the LONGIN_CONNECT string into multiple languages and I want to test if the string is translated.
More globally, is there a a way test if something is different ? ... don't have a class, don't exists on the page, is not selected, ...

It is definitely worth looking at the API docs. I have these open pretty much all the time.
There are lots of Web Driver functions you can use like isEnabled(), isDisplayed(), isSelected() etc. Protractor uses Jasmine syntax so you can use '.toBe(false)' to assert things are false.
To check for classes, you can do something like:
expect(myElement.getAttribute('class')).toContain('my-class-name');
To compare strings and assert that they do NOT match you could use .not. Jasmine docs
say:
Every matcher's criteria can be inverted by prepending .not:
expect(x).not.toEqual(y); compares objects or primitives x and y and
passes if they are not equivalent

You can use something like:
expect(model.getText()).not.toContain('abcdef');
There is a .not property nowadays.

I'm using the following to check for NOT matching:
expect(element('legend').text() === "LOGIN_CONNECT").toBe(false);

Related

In Mockito Flutter how to write a matcher to match Any except specified?

To set the context, I am trying to do this in Flutter.
For example,
I have a test that passes, "if I set my mock to say 'no network connection' and expect 'NetworkUnavailable' to result."
Then, I thought to write next test that "if network is available, result could be anything except 'NetworkUnavailable'"
I am struggling to setup an expect matcher for that. Does Mockito has something for this, something like AnyExcept([matcher])?
There is an isNot Matcher that you can combine with other Matchers. So, for example, you should be able to do something like: expect(valueToTest, isNot(unwantedValue)); or expect(valueToTest, isNot(isIn([unwantedValue1, unwantedValue2])));
If that doesn't do quite what you want, you also can use the predicate to easily create your own Matcher from a boolean function.
(You might not have found these if you were searching the Mockito documentation
because they're part of package:matcher (normally included as part of package:test); they're used for unit tests in general, not just for mocks.)

Do we have something similar to Pass, Continue and Break statement in Karate? [duplicate]

Find the example here.
def a = condition ? " karate match statement " : "karate match statement"
Is it possible to do something like this??
This is not recommended practice for tests because tests should be deterministic.
The right thing to do is:
craft your request so that the response is 100% predictable. do not worry about code-duplication, this is sometimes necessary for tests
ignore the dynamic data if it is not relevant to the Scenario
use conditional logic to set "expected value" variables instead of complicating your match logic
use self-validation expressions or schema-validation expressions for specific parts of the JSON
use the if keyword and call a second feature file - or you can even set the name of the file to call dynamically via a variable
in some cases karate.abort() can be used to conditionally skip / exit early
That said, if you really insist on doing this in the same flow, Karate allows you to do a match via JS in 0.9.6.RC4 onwards.
See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397
The result of karate.match() will return a JSON in the form { pass: '#boolean', message: '#string' }
If none of the above options work - that means you are doing something really complicated, so write Java interop / code to handle this

How to use match keyword inside if condition for UI automation using Karate? [duplicate]

Find the example here.
def a = condition ? " karate match statement " : "karate match statement"
Is it possible to do something like this??
This is not recommended practice for tests because tests should be deterministic.
The right thing to do is:
craft your request so that the response is 100% predictable. do not worry about code-duplication, this is sometimes necessary for tests
ignore the dynamic data if it is not relevant to the Scenario
use conditional logic to set "expected value" variables instead of complicating your match logic
use self-validation expressions or schema-validation expressions for specific parts of the JSON
use the if keyword and call a second feature file - or you can even set the name of the file to call dynamically via a variable
in some cases karate.abort() can be used to conditionally skip / exit early
That said, if you really insist on doing this in the same flow, Karate allows you to do a match via JS in 0.9.6.RC4 onwards.
See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397
The result of karate.match() will return a JSON in the form { pass: '#boolean', message: '#string' }
If none of the above options work - that means you are doing something really complicated, so write Java interop / code to handle this

Best way to implement behavior based in type in scala

In a friendly chat that I was having with a friend during a code review we notice that in the code there was a lot of:
unknownTypeVal match {
case asStr: String => //DO SOMETHING FOR STRING
case asInt: Integer => //DO SOMETHING FOR Integer
case asMyOwnClass: MyOwnClass => //DO SOMETHING FOR MyOwnClass
}
problem that was initially generated by methods that return Any or Option and there is no way to remove that because we are using libraries as XPath, and JSONPath, which return instances of Any or Option for a provided path.
I don't want to get into discussions of "preference", this is not an opinion question, I want to know either by standard defined preferably by Scala, or any other organization of impact, to do this kind of "type checking" in code in a more organized way, we think that this functionality can be reduced to a single function call to a method which contains a map of function and based on "something" (name of the class or something else that I do not know right now) determine how to process such parameter:
process(myAnnonimusVal: Any) = myMapOfFunct(myAnnonimusVal.getClass) //and based on the function that this will return execute such function pasing myAnnonimusVal
what is encouraged to do by Scala devs or Scala community
In principle, match is the cleanest way to execute code conditional on matching the Any type to something else. Any chain of if-else, instanceOf, etc is bound to turn out to be even more cumbersome and less elegant. A possible exception is a case where you know what the actual type is and can act accordingly, where a direct cast might be permissible.
That said, if you find yourself making the same matches many times, you might as well encapsulate the match in order to avoid code repetition. A partial function might be exactly what you have in mind here.

in Mongoid 3, can I build a Queryable and then pass it to a where method?

The docs between Origin and Mongoid aren't really clear on how to use a Origin::Queryable object. Can I build a Origin::Queryable object up and then pass it to a ModelName.where method? It seems that I can't but on the other hand, seems like a completely sensible thing to do. I can picture a situation where I build a Queryable based on some logic, then pass that to the Model's where clause. Is this possible and I'm just not doing it right?
This is what I'm picturing:
class Criteria
include Origin::Queryable
end
criteria = Criteria.new
criteria.where(category: 'vacuum').ne(dept: 'home')
vacuums = Product.where(criteria)
That's how I'm thinking it would work, but it doesn't. What do I do with the Criteria object after I build it?
So it works like this:
c = Criteria.new
c = c.where(category: 'a').ne(dept: 'home')
Then you have your criteria c , now you just use it, if you are using the 10gen driver you can use like this:
collection.find(c.selector, c.options)
Or using Moped:
session[:collection].find(c.selector).select(c.options.fields)
this should work, just did some local tests and it was fine for me.