Unable to click on SwitchPreference with Espresso Ui Test (Android) - android-espresso-web

I am having one SwitchPreference (PreferenceFragmentCompat) and wanted to click on the toggle button. But I am unable to do so.
Here’s my code:
#Test
fun settings_testSwitch() {
pressAudioOnlyToggle()
}
fun pressAudioOnlyToggle() {
onData(allOf(`is`(instanceOf(Preference::class.java)), withText(“Audio only"))).perform(click())
}
I am getting one error like the following:
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: is assignable from class: class android.widget.AdapterView
Any idea how to solve it?

As you are using PreferenceFragmentCompat, so you need to pass recycler_view as the id, because PreferenceFragmentCompat uses a RecyclerView internally. And then you need to use RecyclerViewActions.actionOnItem.
Let’s look at the code below:
fun pressAudioOnlyToggle() {
Espresso.onView(ViewMatchers.withId(androidx.preference.R.id.recycler_view))
.perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
ViewMatchers.hasDescendant(ViewMatchers.withText("Audio only")),
ViewActions.click()
)
)
}
This will press on the switch and turn it on (if it was off previously).

Related

TornadoFX/JavaFX treeview doesnt repopulate correctly after mutating multiple ObservableList

Problem description
I have a treeview (TornadoFX) which gets populated with 3 Observable Lists. If I mutate the 3 lists (first clear them than add new content) the treeview only contains the content of one of the Observable Lists.
The interpretation of my debugging
The treewiev actualises itself in the moment the first List haves its new content and the other 2 are still empty. It does not actualise itself as soon as the other 2 Lists gain their new content.
What I have tried so far
calling treeview.root.children.clear() before I mutate the List to empty the treewiev (same outcome)
calling treeview.refresh() after all Lists have been set (same outcome)
My (more or less pseudo) Code
{//Classes
R extends X
A(val name :String) extends X
B(val name :String, val A :String) extends X
C(val B :String) extends X
}
{//this is how the Lists get their content each time
private val aList = observableListOf<A>()
private val bList = observableListOf<B>()
private val cList = observableListOf<C>()
fun setLists(){
a.clear()
b.clear()
c.clear()
//...
a.add(...)
b.add(...)
c.add(...)
}
}
{
treeview<X> {
root = TreeItem(R)
populate{ parent ->
if (parent == root){
aList
} else if (parent.value is A){
bList.filter { it.A == parent.value.name } //works always
}else if (parent.value is B){
cList.filter { it.B == parent.value.name } //works at first start but not after set setLists() get recalled
}else {
emptyList<X>() //not sure if this is really needed but the compiler needs something here
}
}
}
}
Side Question
Ignore this Question if you want: Intelij is able to run my TornadoFX application (from main or from App with the TornadoFX Plugin), but if I try to export it it doesnt run (neither the jar nor the jnlp). Even if I select TornadoFX and all the other Libraries in the Artifact menu. BUT: if I select Native Bundle -> image in the JavaFX tab, the resulting exe (and only the exe) is working. I also tried to create a shadowJar with com.github.johnrengelman.shadow 5.2.0 Plugin but that also didnt work. So how can I export the Program as a jar (a fatjar including TornadoFX in best case)?
Well I don't know if it's the perfect solution but I simply clear the children and populate the treeview again. It works, but if that is the intended way it's not as "reactive" as I thought it is.

Gosu system table query failing in Gunits

I have a Guidewire Gunit for a transformer in gosu which queries the system table to get a description for a result code which is working fine when run on the server but Gunit fails for the same.
I have tried the annotation #ServerTest for Gunit but that is failing as well.
The same code works fine in Gosu scratchpad.
PFA the code snippet as follows:
var resultCodes = Query.make(SystemTable).select().where(\elt -> elt.ResultCode == "AS01")
var description = ""
if(resultCodes != null && !resultCodes.isEmpty())
{
description = resultCodes.get(0).getFullDescription()
}
I'm getting the exception as follows :
java.lang.IllegalStateException: TableMetadataFactory cannot be used before it is started
Thanks,
Deepti
(Suggestion : )If your requirement is just to query based on some values.
Better dont use that .where() condition.
This is like SELECT * FROM <TABLE> and after getting all the data you are picking out your required result.
The best and the actual way is to use like
Query.make(TABLE_NAME).compare(TABLE_NAME#FIELD_NAME,Relop.Equals,"value_to_compare").select();
Query will be like
SELECT * FROM <TABLE_NAME> WHERE FIELD_NAME = FIELD_VALUE_TO_COMPARE;
While running Gunits, GW uses Shadow tables which will be basically empty.
Here if you are using OOTB entities, You can use Builder classes
or if you need to use some custom entities, use bundles to insert data first.
After inserting data into SystemTable (either using builder classes or bundles) run the below code.
var resultCodes = Query.make(SystemTable).compare(SystemTable#ResultCode ,Relop.Equals,"AS01").select()
foreach(result in resultCodes){
description = result.FullDescription
print("Output : "+description);
}
This happens when your RunLevel is set too low. Run levels below "NO_DAEMONS" will not load system tables. The default should be "NO_DAEMONS" so if you have an annotation on your test like this:
#RunLevel(gw.api.system.server.Runlevel.NONE)
either remove it or increase the level.
You can refactor your code like this:
uses gw.testharness.RunLevel
uses gw.api.database.Query
uses org.mockito.Mockito
uses gw.api.database.IQueryBeanResult
#RunLevel(NONE)
class StackOverflowTest {
function testDoQuery() {
var rs = Mockito.mock(IQueryBeanResult<SystemTable>)
var query = Mockito.mock(Query<SystemTable>)
Mockito.when(query.select()).thenReturn(rs)
var stackOverflow = Mockito.spy(new StackOverflow())
Mockito.doReturn(query).when(stackOverflow).getSystemTableQuery()
stackOverflow.doQuery()
Mockito.verify(stackOverflow, Mockito.times(1)).getSystemTableQuery()
Mockito.verify(query, Mockito.times(1)).select()
Mockito.verify(rs, Mockito.times(1)).iterator()
}
class StackOverflow {
function doQuery() {
var resultCodes = getSystemTableQuery().select().where(\elt -> elt.ResultCode == "AS01")
}
protected function getSystemTableQuery(): Query<SystemTable> {
return Query.make(SystemTable)
}
}
}

react-navigation: set the type of screenProps in HeaderProps in Flow

I'm passing custom properties to the screens using the screenProps field of HeaderProps as per docs.
I would like Flow to check its type, too. So I created a custom MyHeaderProps which looks like:
declare type MyHeaderProps = {
screenProps: ScreenProps,
scene: HeaderProps.scene,
scenes: HeaderProps.scenes,
navigation: HeaderProps.navigation,
}
This solution is not very smart though, as it doesn't update with react-navigation. So I tried:
declare type MyHeaderProps = {
screenProps: ScreenProps,
...HeaderProps,
}
But with no success (ie: an error like headerProps.whatever is not detected).
EDIT: correct the union type notation as suggested in the comments and document the new error.
Even a union type doesn't work:
declare type MyHeaderProps = {
screenProps: ScreenProps,
} | HeaderProps
This way when I try to access const { navigation, screenProps } = headerProps it says there's no navigation property.

InDesign SDK : Drag'n'Drop from a Flex Panel

I have a Flex panel, in InDesign, from which I drag an URL. If I drop this URL on a text editor or a web browser, it works. But when I try to drop it on my InDesign document, it's a little bit harder.
I have implemented a subclass of CDragDropTargetFlavorHelper. The drop works perfectly on Windows. But on mac, I have problems in the method CouldAcceptTypes :
DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource, const IDragDropController* controller) const
{
if (0 != dataIter && 0 != target)
{
DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kURLDExternalFlavor);
if (response.CanDo())
{
...
}
}
}
The problem is that response.canDo() answers kTrue on Windows, but kFalse on Mac. I tried to explore the content of dataIter, but a call on dataIter->First() returns nil. I tried a controller->GetItemCount(), which returns 1. But if I try a controller->GetDragItem(1), I get a nil pointer. I have the impress there is no item. Though, the drop works on another app than InDesign, as I said.
Is it a problem of internalization ? Or something else ? It let me dry.
Thanks in advance
-------------------------- EDIT -----------------------------------
I solved this problem, but discovered another one. The flavor sent by the flex panel has been changed, so that it's a text flavor instead of an URL flavor. My method couldAcceptType works now :
DragDrop::TargetResponse AutocatDNDCustomFlavorHelper::CouldAcceptTypes(const DragDropTarget* target, DataObjectIterator* dataIter, const IDragDropSource* fromSource, const IDragDropController* controller) const
{
if (0 != dataIter && 0 != target)
{
// Check for URL Flavor in the drag
DataExchangeResponse response = dataIter->FlavorExistsWithPriorityInAllObjects(kTEXTExternalFlavor);
if (response.CanDo())
{
return DragDrop::TargetResponse(response, DragDrop::kDropWillCopy);
}
}
return DragDrop::kWontAcceptTargetResponse;
}
The problem is now in the ProcessDragDropCommand method. Here is the code :
ErrorCode AutocatDNDCustomFlavorHelper::ProcessDragDropCommand(IDragDropTarget* target, IDragDropController* controller, DragDrop::eCommandType action)
{
// retrieve drop data
IPMDataObject* dragDataObject = controller->GetDragItem(1);
uint32 dataSize = dragDataObject->GetSizeOfFlavorData(kTEXTExternalFlavor) ;
...
}
The problem is the IMPDataObject I get is nil. There is no item in the controller. However, there were items in the CouldAcceptTypes method, in the DataObjectIterator. So, where are my items ?
I tried using a custom CDataExchangeHandlerFor, but could not really understand what its usage was for. It didn't work anyway.
Has anyone an idea ?
Regards,
Rémi
The problem is the argument of the GetDragItem. It is 1 on PC. It is a strange value on Mac (something like 719853). The only dirty solution I found is doing a memcpy from the object retrieved drom the dataIter in the CouldAcceptTypes method, and use it in the ProcessDragDropCommand method.

Resetting target values in a composite effect

We need to be able to handle a "playable" (play/pause/seek) effect in which the nature of the effect cannot be determined at compile time.
The problem we are running into is resetting the target(s) state after the effect has completed. If we manually drag the seek slider back to the beginning, everything works fine. However, if we set the playheadTime of the composite effect back to 0, the effected targets retain their original value until the playheadTime gets to the correct position to effect the target.
Here is a simplified (as much as I could) test case with view source enabled:
http://www.openbaseinteractive.com/_tmp/PlayableEffectTest/
The problem is demonstrated if you let it play to the end, and then hit the play button to start it over.
What is the best way to go about manually resetting the target values given that the exact nature of the effect is unknown?
Many thanks for your time!
edit
I forgot to mention we are using Flex 4.5 preview release.
Have you tried:
effect.reverse()
More info
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/effects/IEffect.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/effects/IEffect.html#reverse()
Well it's a little kludgy, but I was able to accomplish this by calling some internal methods on the effect to capture the start values, then assigned those values to the targets on a reset.
import mx.core.mx_internal;
use namespace mx_internal;
private var _propertyChangesArray:Array;
protected function captureStartValues(effect:Object):void
{
effect.captureStartValues();
_propertyChangesArray = effect.propertyChangesArray;
}
protected function reset(effect:Object):void
{
for each(var change:PropertyChanges in _propertyChangesArray)
{
var target:Object = change.target;
for(var p:String in change.start)
{
if(target.hasOwnProperty(p))
{
var startVal:* = change.start[p];
var endVal:* = target[p];
if(!isNaN(startVal) && startVal != endVal)
{
target[p] = startVal;
}
}
}
}
effect.playheadTime = 0;
}
I don't know if this is the best way to accomplish this, but it seems to be working so far. I am absolutely open to suggestions for a better method.
Cheers!

Resources