Assert attribute does not contain class in DalekJS - dalekjs

In DalekJS you can assert that an element has a class with
test.assert.attr('#logOutButton', 'class').to.contain('ng-hide')
Is it possible to somehow detect if an element does not have a class? When I write
test.assert.attr('#logOutButton', 'class').to.not.contain('ng-hide')
the test just ends without an error (just a warning that done() was not called). So this is maybe a bug and a feature request!?

Related

How to use one of two locators based on other element text/presence in robot framework

How to use two locators for a element in robot framework? if locator 1 doesn't work , it should take locator 2. Below is a code example of what I'm trying but are unable to make work.
${button} Element Should Contain ${QAM} Create button
Run Keyword If ${button} click element ${button1}
... ELSE click element ${button2}
You are close, with the only problem the keyword Element Should Contain being an assertion - if it passes, the case will continue, and if fails - the execution will stop. Being an assert it also doesn't return a value - in general there's nothing to do with such a value, the keyword itself controls the flow.
So to achieve what you need - get the assertion status, without stopping the execution, you have to wrap it in a special keyword just for that Run Keyword And Return Status. What it does is to call the wrapped keyword, and return boolean - True/False did it pass or fail. Here's your code with it:
${button}= Run Keyword And Return Status Element Should Contain ${QAM} Create button
Run Keyword If ${button} click element ${button1}
... ELSE click element ${button2}

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

Jasmine test presence of css selector

Jasmine and Karma, latest version, testing an AngularJS instance.
I tried
expect(element('a.topic-heading-link-10')).toBeDefined();
but it responds
expect undefined toBeDefined undefined
http://example.com/test/e2e/scenarios.js:16:7
expected undefined but was undefined
Not doesn't look very good. What is a better way to test the presence of a CSS selector?
You can use count to ensure your "look up" found something. For instance:
expect(element('a.topic-heading-link-10').count()).toEqual(1);
If the element doesn't exists or it doesn't have that specific class, count() will equal 0.

Customizing failure reporting in TestNG

Background:
I have created a basic playground project that contains:
A testLogin.java file that contains:
a. testng package imports (org.testng.*)
b. selenium webdriver imports (org.openqa.selenium.*)
c. 5 test-methods with testng annotations:
#Test(groups={"init"})
public void openURL()
Contains webdriver code to initiate the webdriver and open a chrome >instance with a given url.
#Test(dependsOnGroups={"init"})
public void testLogin()
Contains webdriver code to:
1. Locate username password text-input elements, enter the username password from a properties file.
2. Locate the "log in" button and click the button to log-in
3. Manage a login-forcefully scenario if someone else has already logged in using the credentials.
#Test(dependsOnMethods={"testLogin"})
public void testPatientsScheduleList()
Contains webdriver code to check if any patients have been scheduled. If yes, then fetch the names and display in console.
#Test()
public void testLogout()
Contains webdriver code to locate the logout button and click on the button to logout of the app.
#AfterTest()
public void closeConnection()
Contains webdriver code to dispose the webdriver object and close the chrome instance.
Currently I am simply running the test script wrapped as testng methods from ANT and a testng-xslt report gets generated.
Issues:
1. Performing validations against every line of code of webdriver script in a test method:
I know:
1. Selenium webdriver script contains API methods (findElement() and others.) that throw exceptions as a result of a default assertion/validation they perform. These exceptions show up in the generated report when a test-method fails.
2. TestNG provides Assert class that has many assertion methods but I have not yet figured out how can i use them to perform validation/assertions against every line of code of webdriver script. I tried adding assertion methods after every line of webdriver script code. What appeared in the output was just an AssertionError exception for a testmethod.
2. Failing a certain test method which gets passed due to try.. catch block.
If I use a try catch block around a set of 2 or more test drive script steps, and if a test-case fails in any of the steps (script line) then the try..catch block handles it thereby showing the test-method as "passed" in the execution report, which actually failed.
3. Creating a custom report which will show desired test execution results and not stack-traces!
When I execute the above script, a testng-xslt report gets generated that contains pass/fail status of each test method in a test-suite (configured in testng.xml).
The test-results only give me whether a test-method has passed or failed and provides an exception's stack-trace which really doesn't provide any helpful information.
I don't want such abstract level of test execution results but something like:
Name | Started | Duration | What-really-went-wrong (Failure)
Can anyone please suggest/ give some pointers regarding:
1. How can I perform validation/assertion against every line of code of webdriver script in a test-method without writing asserts after every script line?
2. How can I fail a certain test method which gets passed due to try catch block?
3. How can I customize the failure reporting so that I can send a failure result like "Expected element "button" with id "bnt12" but did not find the element at step 3 of test-method" to testng's reporting utility?
4. In the testng-xslt report I want to display where exactly in the test-method a failure occurred. So for example if my test-method fails because of a webelement = driver.findElement() at line 3 of a test-method, I want to display this issue in the test-report in the "What-really-went-wrong" column. I have read about testng testlisteners TestListenerAdapter / ITestListener/ IReporter but I don't understand how to use them after checking testng's javadocs.
5. Also, I have to implement PageObject pattern once I am done with customizing the test report. Where would be the right place to perform assertions in a page-object pattern? Should assertions be written in the page object test methods or in the higher level test methods that will use the PageObject classes?
P.S: I am completely new to testng framework and webdriver scripting. Please bear with any technical mistakes or observation errors if any in the post.
How can I perform validation/assertion against every line of code of webdriver script in a test-method without writing asserts after
every script line?
I dont think so. It is the assertions that does the comparison. So u need it.
How can I fail a certain test method which gets passed due to try catch block?
try-catch will mask the assertion failure.(because on assertion failure, an assertion exception is thrown, so if your catch block is like (catch(Exception e)) Assertion failures wont escape the catch block.
How can I customize the failure reporting so that I can send a failure result like "Expected element "button" with id "bnt12" but did
not find the element at step 3 of test-method" to testng's reporting
utility?
You need to use test listeners . TestNG TestListenerAdapter is a good start
Also, I have to implement PageObject pattern once I am done with
customizing the test report. Where would be the right place to perform
assertions in a page-object pattern? Should assertions be written in
the page object test methods or in the higher level test methods that
will use the PageObject classes?
My personal choice is to use assertions in Test methods, since it is where we are doing the actual testing. Page objects contains scripts for navigating inside the web page.
How can I customize the failure reporting so that I can send a failure
result like "Expected element "button" with id "bnt12" but did not
find the element at step 3 of test-method" to testng's reporting
utility?
You can use extent report and testng listener class( in this class use onTestFailure method to customize your failure report).

How to user unloadStyleDeclarations?

I have a flex4 applciation (mx+spark). When I use:
FlexGlobals.topLevelApplication.styleManager.loadStyleDeclarations(skinName, true);
This works fine: new style is applied.
The trouble is when I apply a new style, it mixes both: this happens because I need to Unload style first.
I try to unload it with:
FlexGlobals.topLevelApplication.styleManager.unloadStyleDeclarations("style/normal.swf",false);
And I always got an error:
ReferenceError: Error #1069: La property 0 cannot be found on Number
and there is no default value.
at normal/unloadOverrides()[null/normal-generated.as:721]
at normal/unload()[null/normal-generated.as:676]
Any idea on how to load/unload swf css in Flex4?
The styles will be updated the next time one of the following methods is called with the update property set to true:
clearStyleDeclaration()
loadStyleDeclarations()
setStyleDeclaration()
unloadStyleDeclarations()
Typically, if you call the one of these methods multiple times, you set this property to true only on the last call, so that Flex does not call the styleChanged() method multiple times.
More information here.

Resources