I have a Windows 7 and I am testing an Android Native app using Appium using Java. The framework used is TestNG. I would like to use Jenkins for running smoke testing for builds available in Jenkins. My desired capabilities are listed in #Before. Can we dynamically paremetrize all of the following in Jenkins?
“automationName”
“platformName”
“platformVersion”
“deviceName”
“app”
“appPackage”
“appActivity“
If so How?
Now if I dynamically parametrize, what would happen to the desired capabilities in my script #Before
its quite simple,
in your class you have to include the code which will listen for input from jenkin job.
String deviceName = PropertyUtils.getProperty("deviceName");
and while you configure your job in Jenkins you have to include string parameter like the image below,
and while building, pass the parameter you want for each build,
The value which you passing above will be processed in your code.
Related
Hello I'm launching a Junit test using java using this code:
JUnitCore junit2 = new JUnitCore();
Result result2 = junit2.run(thenameoftheclass.class);
but in my junit original test there are some "VM option" (the IDEA window of cofig for junit). this VM options have the configuration to loggin in an app, are like the user and password system params. But I am not able to insert those params when I am trying to run junit using just a java program
Well guys I was able to find the answer.
First of all you need to know that my project is not maven based.
This methods are cool --->
JUnitCore junit2 = new JUnitCore();
Result result2 = junit2.run(thenameoftheclass.class);
The problem was that when I was building the Application arguments in Intellij IDE I was filling the app password and user in the field "program arguments" but actually it was meant to be field in "VM Options" becase the java machine uses them in execution time
I am building an Elasticsearch plugin based on this example. The plugin uses Gradle for building, testing, integration testing, etc. I want to use IntelliJ to set a breakpoint in an Elasticsearch integration test and debug it. I don't care if I run the Gradle build from within IntelliJ or outside of IntelliJ, but right now in both cases I'm running into issues. I'll describe my setup and the problems below:
First I download and build/test the example project via CLI:
$ pip install cookiecutter
$ cookiecutter gh:spinscale/cookiecutter-elasticsearch-ingest-processor
$ # keep all default settings when prompted...
$ gradle build # (also runs the test and integTest tasks)
This runs fine and the tests pass. I generate the IntelliJ project using Gradle ($ gradle idea) and open it in IntelliJ (shows a green Gradle icon on the directory). I use the default gradle-wrapper option and keep all other defaults when opening.
First problem: I open IntelliJ's Gradle window (view > Tool Windows > Gradle), but I don't see any of the Gradle tasks which I know are defined in the project. This doesn't seem to be a huge deal, but it would be nice to have them.
Now I want to run the tests within IntelliJ, so I open the tests in org.elasticsearch.plugin.ingest.awesome.AwesomeProcessorTests. This class extends the ESTestCase class from Elasticsearch but doesn't directly test any Elasticsearch API interaction.
Second problem: I run this test class using the little green triangles next to the class name. This fails with the error java.lang.RuntimeException: unable to install test security manager.
I figured out I can get around this by editing the run configuration and adding the VM argument -Dtests.security.manager=false. Now the simple tests run and pass, and I can also set breakpoints and debug them.
Now I want to directly test some Elasticsearch functionality, so I write a new integration test class that extends the class ESIntegTestCase. The test should hit the Elasticsearch _cat/plugins endpoint and check that the response string is non-empty.
public class SimpleIT extends ESIntegTestCase {
private RestClient restClient;
#Before
public void setUp() throws Exception {
super.setUp();
this.restClient = getRestClient();
}
#Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singletonList(IngestAwesomePlugin.class);
}
public void testPluginInstallation() throws IOException {
Response response = restClient.performRequest("GET", "_cat/plugins");
String body = EntityUtils.toString(response.getEntity());
assertTrue(body.length() > 0);
}
}
When I run this via CLI (gradle integTest), the test passes. If I add a purposely-failing assertion (e.g. assertTrue(body.length() < 0), then the test fails. So that seems to work.
Third problem: When I run the same test from within IntelliJ (little green triangles), I get the error:
java.lang.IllegalArgumentException: no hosts provided
at __randomizedtesting.SeedInfo.seed([6F620686489164F5:270C27B7060A2BA1]:0)
at org.elasticsearch.client.RestClientBuilder.<init>(RestClientBuilder.java:68)
at org.elasticsearch.client.RestClient.builder(RestClient.java:124)
at org.elasticsearch.test.ESIntegTestCase.createRestClient(ESIntegTestCase.java:2261)
at org.elasticsearch.test.ESIntegTestCase.createRestClient(ESIntegTestCase.java:2248)
at org.elasticsearch.test.ESIntegTestCase.createRestClient(ESIntegTestCase.java:2242)
at org.elasticsearch.test.ESIntegTestCase.getRestClient(ESIntegTestCase.java:2236)
at org.elasticsearch.plugin.ingest.awesome.SimpleIT.setUp(SimpleIT.java:36)
This maps to the line where I call getRestClient(), meaning IntelliJ is blocking the Gradle/Elasticsearch integration testing setup which otherwise works from the CLI.
FWIW, I can still set a breakpoint on this line and debug the test class in IntelliJ and it will stop at the line.
Now I try to run the integration tests via CLI, set a breakpoint in IntelliJ, and use IntelliJ's remote debugger to attach to the tests.
I setup a new "Remote" run configuration, keeping the defaults (transport socket, debugger mode attach, host localhost, port 5005). On the "Search sources using module's classpath" option, I've tried all the possible settings.
I set a breakpoint on the getRestClient() line, and run Gradle with remote debugging options via CLI:
$ GRADLE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005" gradle integTest
Fourth problem: As expected, the Gradle process suspends, showing Listening for transport dt_socket at address: 5005. I start the new remote task in IntelliJ, and then the Gradle process continues running. Unfortunately it runs all the way through and doesn't stop at the breakpoint. The tests still pass.
I've searched online extensively for different ways to attach to the Gradle debugger. I've seen many things about disabling the daemon, and I've also tried using --system-prop to pass the debug parameters, but nothing solves this problem so far.
In my Selenium-TestNG-Maven automation framework, I am have properties file for storing 'application-url'. The Jenkins job is configured for this. I have to run this test suite on QA/Stage/Production server based on need. But not sure how can I dynamically provide or override the 'application-url' property used in the code. (Environment Injector plugin? How?)
As per code, Selenium WebDriver instance in created, then java code reads the properties file and same URL is used by Selenium instance to open a webpage.
I dynamically provide URLs by using the choice parameter for my Jenkins job.
First select this project is parameter as pictured below:
Then select the Add Parameter > Choice Parameter as pictured below:
Then save.
Now when you are building you will be able to select the url to use for that particular build, like this:
And when you need to reference the url, you can pass it through to maven by using the $URL in the Maven Goals.
ADDED: Here is an example of how I am using the choice parameter in the Maven goals
I am passing the ${browserName} parameter that is defined using the Choice Parameter through maven which will be referenced using the system property "browser". So when I want to get the value in my code, I just use
System.getProperty("browser");
And I am able to access that passed parameter.
You can configure your jenkins to pull the latest code from any of the repository (Github, SVN) and in the Execute Shell build step, you can write a shell script to achieve the same.
I am writing Web based application automation test script using cucumber,selenium webdriver, Java and gradle.
I have around some 25 feature files.
I need to test this 25 feature files parallel as well as in sequence manner.
Currently, I am running the one test at a time by using test name.
Is there any way to run the test in parallel as well as concurrent manner?
You can do parallel execution if you provide different cucumber runner classes.
Then you can configure the Test tasks in Gradle to run in parralel:
tasks.withType(Test) {
maxParallelForks = 4
}
And you need to define a test Task which executes your cucumber runners (in this example all have a Cucumber in their classname)
task cucumberTests(type: Test){
includes = ['**/*Cucumber*']
}
Maybe this will help you
P.S. Regarding the sequential running: Cucumber doesn't guarante any running order of the different feature files
If you are open to using Maven, here is the example I used. Worked great for me!
https://opencredo.com/running-cucumber-jvm-tests-in-parallel/
I need to run project tests both locally and automatically on TeamCity server.
Local test execution must use local database connection, and when run on TeamCity, tests must use a remote connection to the database.
So I need to tell my tests, when to use local connection and when to use remote and pass URL, username and password in this case.
To tell that I decided to use java system properties. I found built-in support in Gradle for that
systemProperty 'some.prop', 'value'
The question is, how can I create a standard test task for local test run, that will not pass any properties, and a custom test task, that will set system properties before run?
I tried something like
task teamCityTest(type : Test) {
scanForTestClasses = false
includes = ['**/*Test.class']
systemProperty 'some.prop', 'value'
}
but it failed with NPE, that means I'm doing something wrong.
The approach is fine (you can use the Java plugin's test task for running tests locally), but you'll have to configure further properties for teamCityTest such as classpath = configurations.testRuntime (or even classpath = test.classpath). For a full example, see samples/java/withIntegrationTests in the gradle-all distribution.