how should i find a global key in flutter driver test? - flutter-test

Normally I put Key: ValueKey in a flutter element that I want to find in my test cases for testing, however this particular element already has a globalKey. So, what should I use to find the globalkey used in the element?
value key
key: ValueKey('nameField')
In test case =>
final nameField = find.byValueKey('nameField')
global key
final LabeledGlobalKey<FormFieldState<String>> _passwordField = LabeledGlobalKey<FormFieldState<String>>("passwordFieldKey")
key: _passwordField
In test case =>
final passwordField = find.???('???')

I don't think it's possible to find a GlobalKeys (that I used to find the position of certain widgets), but what you can find is Keys. So what I did is: Wrap the widget that I had to find in my test by a Container Widget that had that GlobalKey.
GlobalKey someKeyName = GlobalKey();
Container(
key: someKeyName,
child: CustomButton(
key: Key('Key that I would look for in my Integration Test'),
child: Text('Press Me'),
),
);
I am not sure of what LabeledGlobalKey<FormFieldState<String>> does, but hope this work around will help you solve your issue.

Related

Cypress assertion for element propery

I'm writing a test in cypress to test if a video is playing. Unfortunately, this can't be achieved through code such as:
cy.get('video')
.should('have.prop', 'paused', false)
.and('have.prop', 'ended', false);
I do have an a solution in mind that I'm having trouble executing. The video element has a property currentTime that will be higher than 0 if the video is streaming. I've tried several ways of declaring this to a variable and making an assertion based on that variable.
cy.get('video')
.should('have.prop', 'currentTime')
.then((x) => {
// x is the class prop
expect(x).to.be.greaterThan('0');
});
However, cypress doesn't interpret the value as an integer. Any advice on how I could go about this problem?
The currentTime prop is already a number, but you compare it a string, so Cypress gives you the message
AssertionError: the argument to above must be a number
This refers to '0', not x.
Try
expect(x).to.be.greaterThan(0);

Is there any way to find the runtime values of a Selector with testcafe and VS Code

I am trying to debug a testcafe test with node from VSCode and want to verify that the selector used in the code identifies the correct element and retrieve the values of the variables that is declared in a function / variable assigned with a selector.
I start the test.js file in debug mode with command:
"C:\Program Files\nodejs\node.exe" --inspect-brk=21496 testcafe.js chrome tests.js --env=dev --skip-js-errors
The test stop at the breakpoint and when the below line is reached, i wanted to verify what exactly is inside that variable (element) such that i can verify if the selector is selecting the desired element.
let element= Selector(".unique_selector_class").parent(2);
I expect to find the properties of the selected element in the debug mode. e.x., length of the 'element' if its an array, outertext of the element.
Update:
I think what i said earlier was little confusing. I have a method like this which is called by a test.
`async deleteSelectedComponentsMethod()
{
let element = await Selector(".uniqueSelectorClass");
let numberOfSelectedComponents = element.length;
for (let i = 0; i < numberOfSelectedComponents; i++)
{
await t.click(deleteSelectedComponent.nth(i));
}
}`
In this method i wanted to see what is inside the variable 'element', so that i can write a logic as in the code. PS: the element am trying to identify will be visible only when the mouse is hovered.
The value in the variable 'element' returns a function that does not help to find the runtime values in the element
UPDATE:
Selector doesn't return an array when multiple elements match it. Use await selector.count to retrieve the number of matched elements and selector.nth() to enumerate them:
async deleteSelectedComponentsMethod()
{
let element = Selector(".uniqueSelectorClass");
let numberOfSelectedComponents = await selector.count;
for (let i = 0; i < numberOfSelectedComponents; i++)
{
await t.click(deleteSelectedComponent.nth(i));
}
}
Read more about the selector.count property in the Using Selectors article.
ORIGINAL ANSWER:
You can use the await keyword to retrieve information about elements represented by Selectors. Once we will implement this feature: #3244, you will be able to debug Selectors by typing selector expressions in the browser console.

How to make Jenkins Build Parameters Sticky? (Retain last choice for next run)

Problem
We want some jobs to start with defaults and modify job. E.g., A deploy into a test environment should default to the last settings. At present, we can configure the job prior to running. This is OK but cumbersome.
You can define props in the job manually or programmatically via properties. If we do this programmatically, then we can update them once they have been selected. The first call sets the properties for the build and the 2nd changes it to user selection. In theory, if you set these manually, you'd only need the 2nd call
def stickyprops(def sticky = "initial value") {
def propertiesAllBranches = [
disableConcurrentBuilds(),
[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[$class: 'StringParameterDefinition', defaultValue: sticky, description: '', name: 'STICKY_PARAM']]
]
]
properties(propertiesAllBranches)
}
node() {
// set to default
stickyprops()
// Report current user choice
currentBuild.description = "param ${params.STICKY_PARAM}"
// Set params to user choice
stickyprops(params.STICKY_PARAM)
}
This defines a build parameter with an initial value so the first time you run the build, this initial value will be used. When another build with a different value (e.g. "new value") is triggered ("Build with Parameters"), this "new value" will be used by default.
parameters {
string name: 'STICKY', defaultValue: params.STICKY?:'initial value'
}
I don't understand your exact use case but this answers the question "How to make Jenkins Build Parameters Sticky? (Retain last choice for next run)" for me.

Flutter: validating Radix 10 numbers

I was testing validation of numbers on my iPhone.
Here is my code snippet:
child: new TextFormField(
controller: sales,
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
filled: true,
fillColor: CupertinoColors.white,
border: const OutlineInputBorder(),
labelText: ‘Sale amount’,
suffixText: ‘ZAR’,
suffixStyle:
const TextStyle(color: Colors.green)),
maxLines: 1,
validator: (val) {
if (val.isEmpty ) return 'Amount is required';
if (val.contains(",")) {
sales.text = val.replaceAll(new RegExp(r","), ".");
}
if (sales.text.indexOf(".") != sales.lastIndexOf(".")) {
return 'Enter valid amount.';
}
else
return null;
},
),
Now, I'm testing the validation with this number 25,52,85 - this is obviously not a valid number but it is a possibility that is allowed on iPhone's number softkeyboard. (Also interesting to note, on the US iPhone, we have commas on the number softkeyboard instead of fullstop and if one had to store a double, the commas have to be converted into fulstops, which I have done in the validate method in the code above)
Now, when I click "Done" to validate the form, an error results in the log and it tells me that it is an invalid Radix 10 number. In other words, Flutter is telling me that a double cannot exist with two commas / fullstops within it.
So to solve this, I wrote in this piece of code under validate to test if the number contains more than 2 fullstops:
if (sales.text.indexOf(".") != sales.lastIndexOf(".")) {
return 'Enter valid amount.';
}
However, I find this to be cumbersome and was wondering if there was a way to test this more elegantly? How can I validate that a number is a valid number in flutter easily?
.parse is your guy. Either double.parse in case you want decimals, or int.parse if you did not.
Check this other StackOverFlow answer that explains this with examples

Does CKEDITOR.htmlParser.element.remove() also remove children?

Does CKEDITOR.htmlParser.element.remove() remove the element and its descendants or does it just remove the element and stuff its immediate children into its place? I ask because I've tried a number of approaches to removing elements from consideration during a filter and have wound up with not quite the results I expect; removing the element seems not to remove everything it ought to, but perhaps it's intended behavior.
If the latter, what is the most efficient way to remove an element and everything inside it? setHtml()?
The CKEDITOR.htmlParser.node.remove removes the node which means also its children are removed.
// Removing `em` element on `setData`.
CKEDITOR.instances.editor1.on( 'toHtml', function( evt ) {
var ems = evt.data.dataValue.find( 'em', true );
console.log( 'Before: ' + evt.data.dataValue.getHtml() );
if ( ems.length ) {
ems[ 0 ].remove();
}
console.log( 'After: ' + evt.data.dataValue.getHtml() );
}, null, null, 14 );
See this codepen demo.
It is hard to speculate on your case without seeing any code, but I assume you are trying to manipulate some copy of the element or partial tree which is not used any further so it may seem this method does not work as expected.
If you provide the code, it will be easier to check if there are any issues with it.

Resources