jeudi 1 mars 2018

Generic code for clicking web element from a list in Python:

Here is my code in Java that I want to convert in Python:

public static void clickElementFromList(String ListObject, String strname) {

    List<WebElement> wbeElement;

    wbeElement = Util.findElements(ListObject);

    for (int cnt = 0; cnt < wbeElement.size(); cnt++) {
        if (wbeElement.get(cnt).getText().trim().contentEquals(strname)) {
            wbeElement.get(cnt).click();
            break;
        }
    }

}

//listobj is the web element. //strname is the displayed text in the application

Simulate functions in parent component React that are being passed down via Props

   onClickOfCreateAccountButton() {
        const el = document.getElementsByClassName('SignInSlider-loginSlider')[0];
        const el1 = document.getElementsByClassName('SignInSlider-createAccountSlider')[0];

        el.classList.add('SignInSlider-animate-show');
        el.classList.remove('SignInSlider-animate-hide');
        setTimeout(() => {
            this.props.signInSliderActions.openCreateAccountPage();
            el1.classList.add('SignInSlider-animate-show');
        }, 5);
    }

    onClickPasswordReset() {
        const el = document.getElementsByClassName('SignInSlider-loginSlider')[0];
        const el1 = document.getElementsByClassName('SignInSlider-passwordSlider')[0];

        el.classList.add('SignInSlider-animate-show');
        el.classList.remove('SignInSlider-animate-hide');
        setTimeout(() => {
            this.props.signInSliderActions.openForgotPasswordResetPage();
            el1.classList.add('SignInSlider-animate-show');
        }, 5);
    }

I am trying to test the above functions however their click is being called from the Child Component as shown below:

My render code:

    render() {
    const { deviceType, preferences, messagesTexts, signInSliderDetails } = this.props;
    const { showCreateAccountPage, showWelcomePage, showForgotPasswordPage, createAccount,
         signInDetails, passwordResetResponse } = signInSliderDetails;
    const passwordResetDetails = { passwordResetResponse };
    const hideBackArrowCloseButton = !(showCreateAccountPage || showForgotPasswordPage);
    return (
        <SlidePanel
            isOpenPanel={this.props.isOpenPanel}
            onClosePanel={!hideBackArrowCloseButton && this.onBackButtonClick}
            onPrimaryCloseButtonClick={this.onPrimaryCloseButtonClick}
            panelTitle={!hideBackArrowCloseButton && 'Back to Sign-In'}
            hideBackArrowCloseButton={hideBackArrowCloseButton}
            isPrimaryCloseButtonRequired>

            <div className={cx('signInSliderPanel')}>

                <div className={cx('loginSlider')}>
                    { !showCreateAccountPage && !showWelcomePage && !showForgotPasswordPage &&
                    <LoginWrapper
                        signInDetails={signInDetails}
                        deviceType={deviceType}
                        preferences={preferences}
                        messagesTexts={messagesTexts}
                        source="account"
                        actions={this.props.signInActions}
                        onClickOfCreateAccountButton={this.onClickOfCreateAccountButton}
                        onClickPasswordReset={this.onClickPasswordReset}
                        isSignInSliderReq
                    /> }
                </div>

                <div className={cx('createAccountSlider')}>
                    {showCreateAccountPage &&
                    <CreateAccountWrapper
                        createAccount={createAccount}
                        isSignInSliderReq
                        deviceType={deviceType}
                        messagesTexts={this.props.messagesTexts}
                        preferences={this.props.preferences}
                        actions={this.props.createAccountActions}/> } </div>
                <div className={cx('passwordSlider')}>
                    {showForgotPasswordPage &&
                    <PasswordResetWrapper
                        isSignInSliderReq
                        messagesTexts={messagesTexts.passwordReset}
                        preferences={preferences}
                        createAccountActions={this.props.createAccountActions}
                        actions={this.props.passwordResetActions}
                        passwordResetDetails={passwordResetDetails}
                        signInSliderActions={this.props.signInSliderActions}
                        onPrimaryCloseButtonClick={this.onPrimaryCloseButtonClick}
                        deviceType
           />} </div>
                <div className={cx('welcomeSlider')}>
                    { showWelcomePage &&
                    <Welcome
                        messagesTexts={messagesTexts.signInSlider}
                        firstName={TokenProvider.get('DP_USER_NAME')}/>} </div>
            </div>
        </SlidePanel>
    );
}

My test functions:

    describe('Shallow Render', () => {
    let wrapper;

    beforeEach(() => {
        TokenProvider.get.withArgs('DP_USER_NAME').returns('Vini');
        wrapper = shallow(
            <SignInSlider
                {...props}
                />,
            );
    });

    afterEach(() => {
        wrapper.unmount();
        TokenProvider.get.withArgs('DP_USER_NAME').returns('');
        TokenProvider.get.reset();
    });

    it('it rendered successfully', () => {
        expect(wrapper.find('SlidePanel')).to.exists;
    });

    it('it shows createAccountPage SignInSlider', () => {
        wrapper.setProps({
            signInSliderDetails: {
                createAccount: {},
                signInDetails: {},
                passwordResetDetails: {
                    passwordResetResponse: {},
                },
                showCreateAccountPage: true,
                showWelcomePage: false,
                showForgotPasswordPage: false,
            },
        });
        wrapper.update();
        expect(wrapper.find('CreateAccountWrapper')).to.exists;
    });

    it('it shows Forgot password page SignInSlider', () => {
        wrapper.setProps({
            signInSliderDetails: {
                createAccount: {},
                signInDetails: {},
                passwordResetDetails: {
                    passwordResetResponse: {},
                },
                showCreateAccountPage: false,
                showWelcomePage: false,
                showForgotPasswordPage: true,
            },
        });
        wrapper.update();
        expect(wrapper.find('PasswordResetWrapper')).to.exists;
    });

    it('it shows Welcome page SignInSlider', () => {
        wrapper.setProps({
            signInSliderDetails: {
                createAccount: {},
                signInDetails: {},
                passwordResetDetails: {
                    passwordResetResponse: {},
                },
                showCreateAccountPage: false,
                showWelcomePage: true,
                showForgotPasswordPage: false,
            },
            firstName: 'Vini',
        });
        wrapper.update();
        expect(wrapper.find('Welcome')).to.exists;
    });
});

Open Modal and Page with cypress and Ionic 3

I build an Ionic 3 project and I want to test it with Cypress. I can access to my app and run some simple test. But when I try open page of modal, nothing append and my test fail.

it('should open history', () => {
        // Button to open my page : OK
        cy.get(open_history_button).click();

        // Check if a label exists in the opened page : FAIL
        cy.get(history_no_event_label).contains("All is ok !");
    });

Cypress success to click on the button but the page doesn't appear.

Someone have an idea to solve that ?

Unable to run android instrumentation testcase ( Kotlin ) in android studio

I have written simple instrumentation test in kotlin as below

@RunWith(AndroidJUnit4::class)
class SampleTestCase {

    fun testCaseCheckPackageName() {
        val appContext = InstrumentationRegistry.getTargetContext()
        assertEquals("com.niks.sample1", appContext.packageName)
    }        
}

Everything works fine when i am creating androidTest apk & even testcase are running fine but throwing below stacktrace in android studio.

java.lang.TypeNotPresentException: Type android.support.test.runner.AndroidJUnit4 not present

    at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
    at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
    at com.sun.proxy.$Proxy2.value(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: android.support.test.runner.AndroidJUnit4
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
    at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:349)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.Class.createAnnotationData(Class.java:3521)
    at java.lang.Class.annotationData(Class.java:3510)
    at java.lang.Class.getAnnotation(Class.java:3415)
    at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:220)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:46)
    ... 3 more

How to Sequencing Tests from a Test Suite.

Please help me sequence the tests in a Test Suite. I have 2 test classes each having 3 test methods.

First Class

public class FirstClass  {

@Test(priority =1)
public void FirstMetod()
{
    System.out.println("First Method of First Class");
}


@Test(priority =2)
public void SecondMetod()
{
    System.out.println("Second Method of First Class");
}

@Test(priority =3)
public void ThirdMetod()
{
    System.out.println("Third Method of First Class");
}
}

Second Class

public class SecondClass {

    @Test(priority =1)
    public void FirstMetod()
    {
        System.out.println("First Method of Second Class");
    }


    @Test(priority =2)
    public void SecondMetod()
    {
        System.out.println("Second Method of Second Class");
    }

    @Test(priority =3)
    public void ThirdMetod()
    {
        System.out.println("Third Method of Second Class");
    }
}

testng.xml

<suite name="Suite">
<test thread-count="5" name="Test">
    <classes>
        <class name="sample.testng.FirstClass" />
        <class name="sample.testng.SecondClass" />
    </classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

The Results are as follows.

First Method of First Class
First Method of Second Class
Second Method of First Class
Second Method of Second Class
Third Method of First Class
Third Method of Second Class

But I need to run the second class after first class. So the desired results should be.

First Method of First Class
Second Method of First Class
Third Method of First Class
First Method of Second Class
Second Method of Second Class
Third Method of Second Class

I have tried grouping and depends on methods also, but could not achieve the desired sequence.

Johansen Test in R

There is a test result Johansen on cointegration.

> library("urca")
> summary(ca.jo(data.frame(price.fut.ms, price.spot.ms), type="trace", K=2, ecdet="none", 
spec="longrun"))

###################### 
# Johansen-Procedure # 
###################### 

Test type: trace statistic , with linear trend 

Eigenvalues (lambda):
[1] 0.19914009 0.01814878

Values of teststatistic and critical values of test:

          test 10pct  5pct  1pct
r <= 1 |  4.36  6.50  8.18 11.65
r = 0  | 57.21 15.66 17.95 23.52

Eigenvectors, normalised to first column:
(These are the cointegration relations)

                 price.fut.ms.l2 price.spot.ms.l2
price.fut.ms.l2         1.000000         1.000000
price.spot.ms.l2       -1.008907         0.443137

Weights W:
(This is the loading matrix)

                price.fut.ms.l2 price.spot.ms.l2
price.fut.ms.d       -0.2588310      -0.02235570
price.spot.ms.d       0.2902789      -0.02219381

How can I pull -1.008907 from the test results. In the description of functions ca.jo, nothing concrete is given on this matter

Red Light for Error Status triggered by USB

We have a fairly complex software running and three large monitors that show kibana reports about that system. Sadly we don't look often enough at these monitors.

I created a test for the whole system and I want to display the status of that test with a signal lamp (similar to a fire truck, red, bright, turning) so we would imidiatly know when something is wrong.

We could use similar setups in other locations, so I want to set this up in a way that it can be reused.

At the moment we provide the raspis with a webinterface where the displayed urls can be configured so they just have to be attached to a powersource and a monitor and work.

The perfect scenerio would be that by attaching a light and configuring an API-endpoint that tells wether or not the lamp should be on or off, everything would also work out of the box.

If have never done anything like this.

1.) Can I controll a lamp like this from the browser with javascript?

2.) Do I have to install some additional software on the raspis for that or is there a way arround that? We already have 150+ raspies out there and I dont want to update all of them (especially because some of them are thousands of kms away)

3.) How do I search for a lamp like that - I have a hard time finding something suitible. It should be something that I can be sure (enough) to be able to buy again and again.