Organizing Selenium tests in Django - django-testing

I am trying to organize my selenium tests better in a Django project.
I have a folder project/app/selenium_tests/ into which I placed an __init__.py, and a tests.py which contains my selenium tests. in the __init__.py I import the tests like so:
from tests import *
But when I do ./manage.py test app.selenium_tests I get:
ValueError: Test label 'app.selenium_tests' does not refer to a test
What could I be missing here? I even added a models.py to the selenium_test package but no joy.
Any help much appreciated.

you need to put the folder selenium_tests under the tests directory of the app, otherwise the default Django test runner will not find it.
so, move this project/app/selenium_tests/ to project/app/tests/selenium_tests/

Related

Cucumber feature file unable to locate glue code when clicking on Recalculate Steps and throws error message

I am currently working on creating a Test Suite using Cucumber framework. I have created feature files for each of the functionality I have to test.
The feature file never shows the conditions to be covered via glue code. On click of Recalculate steps it throws an error : An internal error occurred during: "Scanning for step definitions".
java.lang.NullPointerException
I tried to change the path of glue in the Test Runner class but it did not solve the problem as well. The feature can be executed without any issue and the code runs fine, only issue is feature files keep on stating that there is no matching glue code.
#OrderInteraction
#Orders
Feature: Validating Order functionality
Background: Pre-requisites of Order Functionality
Given WebDriver is initialized
And Website is up and running
When User Enter "Username" and "Password" as Credentials
Then Validate User Login
Test Runner :
package Cucumber;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features = "Features", glue=
{"src/main/java/CucumberStepDefinitions"})
public class CucumberTestRunner {
}
I would like to find a way in which Cucumber feature files can recognize the glue code present. Feel free to guide me to a existing question which answers this or a documentation which will be of help.
There is a possible solution in this discussion https://github.com/cucumber/cucumber-eclipse/issues/303
Which basically says to make sure you don't have
import cucumber.api.java.en.*;
in your steps files, and to use
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
instead.
Which fixed it for me
I finally was able to find the solution to this issue. Issue lies with the cucumber plugin version, I referred to Cucumber-Eclipse-Update-SiteSnapshot for resolution.
The steps were as below :
1.From Eclipse, go to menu Help > Install New software
2.Work with: https://cucumber.github.io/cucumber-eclipse-update-site-snapshot
3.Select the check-box for Cucumber Eclipse Plugin
4.Select Next as per the instruction shown during installation.
5.Restart your Eclipse after completion of instruction.
Once the plugin was updated Feature file automatically scanned for steps and found the matching glue code.

How to run groovy based JUnit Test Suite from the command line?

How to run the JUnit test suite containing a set of test cases(groovy based) from the command line. Following is the test suite class generated by eclipse.
package com.example.testclasses;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
#RunWith(Suite.class)
#SuiteClasses({ abc.class, xyz.class })
public class AllTests {
}
The above test suite works when I run the above test suite(AllTests)as JUnit from eclipse, however, I want to run the test suite(AllTests) from the command line. How do I do this?
Info: I am using Geb(Groovy) based testing where all the test cases(example: abc, def) are groovy based(having .groovy extension).
If you wish to run your tests from the command line I would suggest using a build system. My personal choice would be to use Gradle but you could probably also get away with using Maven.
The benefit of using a build system, apart from being able to run the tests from the command line, is that it will help you manage your dependencies and it will be easier to build the project for others working on the same codebase - they won't have to manually setup all the dependencies and their versions in the IDE.
Try this:
java -cp /path/to/groovy/embeddable/groovy-all-1.8.1.jar groovy.lang.GroovyShell AllTests.groovy
where 1.8.1 should be replaced with your version of groovy-all-*.jar

grails No tests found for given includes when integration test files anld unit test files both exist

I got a strange problem for grails 3.2.6
I create a integration test and a unit test by grails command
src
--integration-test
--groovy
--it
--test01
--test
--groovy
--ut
--test02
When I run the integrationt-test test01, I got an error
No tests found for given includes
If I delete ut.test02,
I got a message says test passed.
How to solve that?
My hierarchy is created automatically.
Anyway I solved by adding -integration in the configuration command line
like this
test-app it.test01 -echoOut -integration
You are accessing your integration-test at the wrong place.
Please put your hierarchy like this
--test
--integration-test
--groovy
--it
--test01
--groovy
--ut
--test02

Running evosuite generated tests in Eclipse

I have generated the test cases using evosuite from the command line in Linux.
I try to execute the tests in Eclipse. I have imported in my project the evosuite-standalone-runtime-0.2.0.jar.
All the imported classes regarding evosuite are marked with the error sign.
import org.evosuite.runtime.EvoRunner;
import org.evosuite.runtime.EvoRunnerParameters;
import org.evosuite.runtime.testdata.EvoSuiteFile;
import org.evosuite.runtime.testdata.EvoSuiteLocalAddress;
import org.evosuite.runtime.testdata.EvoSuiteRemoteAddress;
import org.evosuite.runtime.testdata.EvoSuiteURL;
I don't understand this. It looks like these classes are unknown even though are in the imported jar file.
Try:
Right button in your project-->build path--> Add External Archives
(select evosuite-0.2.0.jar)
Do not forget to put the two classes in the project. (ESTest.java and ESTest_scaffolding)
I hope this helps.

Import another python script, using PythonInterpreter

I am trying to execute a python method from eclipse using jython. I managed to run it with following code:
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("Mypython.py");
interpreter.eval("MyClassName().MyMethodName()")
My problem is when I import another python script, which exists even in the same directory with Mypython.py. For example, when I add:
from food import Pizza
to Mypython.py, it starts to complain that cannot import. ImportError..
I found some questions about importing python libaries like os, but in my case this is not an issue.
I tried to make the folder as a package, add init.py etc but it failed. I saw some people use PySystemState, but I think it is for jython modules not user python scripts. if this is the solution please give me a simple example.
Could you please help me with that problem.
sys.path is your module-import search path. You can import sys and then modify sys.path as required.