I am writing my first automation program with Selenium RC & i have a couple of queries. Please have a look at the sample code:
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class TestGoogle
{
public static void main(String[] args)
{
Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://google.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
selenium.windowFocus();
}
}
Query 1: In the first argument, i have passed "localhost" because the RC server is running locally on my machine. In case the rc serer is running on a remote machine, how would i pass it. What is the syntax?
Query 2: In the third argument, i have passed "*firefox". I do not understand why is * used when the program runs fine without using it? Also is it also possible to give the absolute path. I have tried it but it is not working?
Kindly suggest,
Regards.
Replace "localhost" with the IP address or DNS hostname of the machine where the Selenium RC server is running.
The *firefox browser-spec specifies Firefox from one of several default locations. If you want a specific location, use the *custom browser-spec.
Selenium RC documentation is at http://selenium.googlecode.com/git/docs/api/java/com/thoughtworks/selenium/DefaultSelenium.html.
Related
At the moment, I have 2 databases, one is local and dev, However, I configured the local one okay using config files and a specific gradle task, this runs okay;
However since Im trying to simulate what would happen in my pipeline, how can I set it up so that reads from the environment variables on my machine, so far this is what I expected;
I checked the environment variable by running
echo $FLYWAY_URL
This returned
jdbc:postgresql://localhost:5432/postgres
Which means variable exists, Next I setup my task like this in gradle;
def jdbcDevUrl = System.getenv()['FLYWAY_URL']
task migrateDev(type: FlywayMigrateTask) {
url = jdbcDevUrl
user = 'myUsr2'
password = 'mySecretPwd2'
locations = ['filesystem:doc/flyway/migrations']
}
However this does not work at all. I have tried to run by not setting up url properties from here hoping it would be picked up automatically but it does not work.
Also using a config file with
flyway.url=${FLYWAY_URL}
does not work. Im using community edition.
All I get is
Unable to connect to the database. Configure the url, user and password!
Any help would be highly appreciated.
From GUI we can follow
Run -> Remote Start -> (select the ip, which we want to run remotely)
From command line also we can specify -R flag to run remote jmeter application.
But here I am creating jmx file using Java and I want run this one from Java only. So, is there any way achieve this
You need to use DistributedRunner class like:
List<JMeterEngine> engines = new LinkedList<>();
Properties remoteProps = new Properties();
//set properties you want to send to remote clients here
DistributedRunner distributedRunner=new DistributedRunner(remoteProps);
List<String> hosts = new LinkedList<>();
//add your JMeter slaves here
hosts.add("remote_host_1");
hosts.add("remote_host_2");
distributedRunner.setStdout(System.out);
distributedRunner.setStdErr(System.err);
distributedRunner.init(hosts, testPlanTree);
engines.addAll(distributedRunner.getEngines());
distributedRunner.start();
For example of creating a JMeter test from Java code using JMeter API check out Five Ways To Launch a JMeter Test without Using the JMeter GUI guide.
Also remember that JMeter is open source so you can look for implementation of this or that functionality directly in JMeter's source code.
You must implement an interface RemoteJMeterEngine. Also, have a look at RemoteJMeterEngineImpl class for reference.
If you have tried running test locally trough Java, this should not be much more complicated to achieve.
I've had problems connecting to a replica set via the C# sharp driver when using the following code:
var client = new MongoClient("mongodb://daluser:daluatmongo#xxx:25015,yyy:25015,zzz:25015/database?replicaSet=dal_uat_mongo");
var db = client.GetDatabase("database");
var collection = db.GetCollection<BsonDocument>("table");
var foo = collection.CountAsync(document => true).Result;
Here xxx, yyy and zzz are IP addresses and I've used anonymous names for the collection and database.
This results in the following exception: "A timeout occured after 30000ms selecting a server using CompositeServerSelector" (more details in gist link):
https://gist.github.com/bfranklinsportingindex/0270a1e958051b689e56
Strangely if we remove the replica set option and only specify one server then it works fine for two of the three servers. The server that fails gives us the familiar "target machine has refused the connection" error.
I'm currently testing directly with the latest version of the source code and the version of mongo on the server we're tryingt to connect to is 2.6.9
I've tried debugging into the source code for the driver amd I get to the following line in SelectServerAsync method in the Cluster class:
var connectedServers = description.Servers.Where(s => s.State == ServerState.Connected);
Here the connectedServers collection is empty and I would expect (with my limited understanding of driver codebase) it to be populated. Hopefully someone with more experience with this codebase can shed any light on what's going on or provide me with some pointers on where to look in the codebase.
Actually we managed to trace the problem down to a network address translation issue which we tested by putting add some lines to the hosts file. The driver seems to be working fine now.
A previous post on this subject has been helpful (see How to export TestExecute/TestComplete results to teamcity?)
Right now, our TestComplete solution creates a text file that MSBuild consumes with a Microsoft.Build.Utilities.Task helper that sends the messages back up to TeamCity. However, I'm wondering if we can do better.
The TeamCity help topic (http://confluence.jetbrains.com/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ServiceMessages) says, messages "should be printed into standard output stream of the build". What I'm trying to figure out is, can I directly access that stream from the TestComplete script?
I was hoping that it would be something as simple as:
dotNET.System.Console.WriteLine_11("##teamCity[testSuiteStarted name='Foo']");
But that is obviously not giving me the correct output stream. Thoughts? Can it be done?
The issue you are experiencing is that TestComplete does not support writing to the standard output stream, even if you invoke the CLR Console.WriteLine, you are writing to the process named tcHostingProcess.exe in which all CLR objects exist.
In order to work around this, you need a console application running that can accept messages from your TestComplete project. There are a number of ways to do this, but here is a proposed solution using TCP/IP for the necessary IPC.
In TeamCity
In the TeamCity build steps, you want the TestComplete or TestExecute process to launch without holding up the build script and then to launch a custom console application which will receive the messages from TestComplete.
start TestComplete.exe [arg1] [arg2] ...
TCConsoleHost.exe
Console Host Application
The console host program will start a TcpListener, and once a client connects, it will read messages from the resulting NetworkStream object and print them to the console. This program will continue until there is an error in reading from the stream (i.e. TestComplete has exited).
class Program
{
static void Main(string[] args)
{
TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 9800);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream stream = client.GetStream();
BinaryReader reader = new BinaryReader(stream);
while (true)
{
try
{
string message = reader.ReadString();
Console.WriteLine(message);
}
catch
{
break;
}
}
}
}
Message Client Class
Likewise, we can create a TcpClient which can connect to our listening process and relay messages. The real trick here is to wrap this in a static class with a static constructor so that once TestComplete loads the CLR bridge, it will automatically connect and be ready to send the messages. This example has a TeamCity service message function SendMessage which automatically formats the message (including escaping single quotes).
public static class TCServiceMessageClient
{
static BinaryWriter writer;
static NetworkStream stream;
static TCServiceMessageClient()
{
TcpClient client = new TcpClient();
client.Connect("127.0.0.1", 9800);
stream = client.GetStream();
writer = new BinaryWriter(stream);
}
public static void SendMessage(string message)
{
writer.Write(string.Format("##teamcity[message text='{0}'", message.Replace("'","|'")));
}
}
In TestComplete
Now, since the client will automatically connect when the CLR bridge is loaded, the only code necessary in TestComplete is:
dotNET["TCServiceMessageClient"]["TCServiceMessageClient"]["SendMessage"]("Hello TeamCity!");
Additional Notes
There are a few caveats with the above code, namely timing, reconnect, etc. A deployed solution should have better error handling of the network conditions. Additionally, it may be more desirable that the TCMessageHost application actually launches TestComplete directly with a System.Process object so that it can more reliably wait for the application to exit.
I'm working with TeamCity and TestComplete as well. I ran into the exact same problem, and you can't write to the console no matter what you try to do, at least not that I've found. I even tried writing a C# app that I used the CLR bridge in TestComplete to talk to it, and still nothing.
What we ended up doing was to create batch file that handles the TestExecute call. We then call the batch file from TeamCity. To call TestExecute use this (with your pjs file and /p specific to your tests):
start /wait TestExecute "{TestCaseID}.pjs" /r /e /p:"{TestCaseID}" /silentmode /forceconversion
Then we check the ERRORLEVEL property returned by TestExecute. A level of 2 means that the test execution failed. In that case, we print the following with an echo statement:
##teamcity[testFailed name='{TestCaseID} - {TestName}' message='TestExecute reported a failure' details='See artifacts']
After TestExecute closes, it will attempt to open the log file. We have our build servers set so that mht files are opened by the calculator since they take a while to open (set it as the default in the Windows Right-Click -> Open With menu). So, after TestExecute completes, it opens the calculator, then our batch file just kills the calculator using taskkill.
We then copy the result file from TestExecute into a specified location (this is a separate executable that we wrote). The we finish the test execution and publish our artifacts to TestExecute:
echo ##teamcity[testFinished name='{TestCaseID} - {TestName}' duration='%milliSecondsElapsed%']
echo ##teamcity[publishArtifacts 'C:\BuildResults\{GroupName}\{TestCaseID}\*.mht']
One thing to note: We were never able to get TestExecute to reliably run a single test at a time, so we actually use a list of our test cases to generate separate pjs and mds files for each of our test cases. Then we use those generated pjs and mds files in TestExecute. That's where the {GroupName}, {TestCaseID}, and {TestName} variables from above come from. Those are specific to our implementation, but you may need different indicators there.
Hope this helps!
If you are using TestExecute this has become "Relatively" simple recently
Execute TestExecute with the following parameters:
/exportlog:"log\Index.html" /SilentMode /DoNotShowLog
For a full rundown of TestExecute parameters check: https://support.smartbear.com/testexecute/docs/running/automating/command-line/command-line.html
Setup your TestComplete project with a build level report:
Please be aware it is case sensitive
On your build configuration, in the general settings tab, export the generated log folder as an artifact.
Once the build has run, you will be able to see the test log embedded within TeamCity:
This is using TestComplete V14 and TeamCity 2019.1
I'm trying to implement scheduler to my application. I use spring and quartz support.
I have test my component and run perfectly.
My Main method is:
public class Main {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("application-context.xml");
}
}
I use wrapper-windows-x86-32-3.5.7, I configure the wrapper.conf, and run from console using DemoApp.bat wrapper.
It works.
But When I want to install the service, I got error message Startup failed: Timed out waiting for a signal from the JVM.
After 5 times repetition, I got error message
JVM did not exit on request, terminated
There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
Thanks for help.
Because it is working fine for you running in a console, but not as a service. This is most likely a problem with the environment of the SYSTEM user. The most common cause is not being able to locate the java binary. The cause should be fairly obvious if you look in the wrapper.log file.
The default location of the java binary is:
wrapper.java.command=java
This will cause it to be found on the PATH. To use a JAVA_HOME location, try the following:
wrapper.java.command=%JAVA_HOME%/bin/java
Then make sure you have declared the JAVA_HOME variable as a SYSTEM WIDE variable, not jsut for your current user account.
Cheers,
Leif