RemoteWebDriver and Grid - is it possible to get the server ip? - ip

I am using RemoteWebDriver from Selenium 2 and Grid to divide my tests on several virtual machines. Let's say I have two Linux machines and in a test I specify the capabilities to run on a Linux machine, I can't figure out which of these two machines is being used.
Is there any way, to figure it out? Something like driver.getServerIp() or anything else?
The reason is, in my Selenium test code I want to start a bash script on the console of the linux machine where the test is being run. Therefore I have to know on which machine the test runs.
Thanks guys!

My java skills aren't the greatest and this code could use some cleaning up, but this works for me.
HttpHost host = new HttpHost(yourHubIP, yourHubPort);
DefaultHttpClient client = new DefaultHttpClient();
URL testSessionApi = new URL("http://" + yourHubIP + ":" + yourHubPort + "/grid/api/testsession?session=" + driver.getSessionId());
BasicHttpEntityEnclosingRequest r = new
BasicHttpEntityEnclosingRequest("POST", testSessionApi.toExternalForm());
HttpResponse response = client.execute(host,r);
JSONObject object = (JSONObject)new JSONParser().parse(EntityUtils.toString(response.getEntity()));
String proxyID = object.get("proxyId"));
proxyID contains the IP of the node.

HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver)driver).getCommandExecutor();
ce.getAddressOfRemoteServer();
Although presumably you'd know the address since you passed it into the constructor for RemoteWebDriver anyway.

Answer provided by Bobble D is working only that there was problem with JSONParser as mentioned by Nilesh as well, here is updated code which can help
HttpHost host = new HttpHost(yourHubIP, yourHubPort);
DefaultHttpClient client = new DefaultHttpClient();
URL testSessionApi = new URL("http://" + yourHubIP + ":" + yourHubPort + "/grid/api/testsession?session=" + ((RemoteWebDriver) driver).getSessionId());
BasicHttpEntityEnclosingRequest r = new
BasicHttpEntityEnclosingRequest("POST", testSessionApi.toExternalForm());
HttpResponse response = client.execute(host,r);
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity()));
String proxyID = object.get("proxyId"));
System.out.println(proxyID.split("//")[1].split(":")[0]);

Related

ScalikeJDBC + SQlite: Cannot change read-only flag after establishing a connection

Trying to get working ScalikeJDBC and SQLite. Have a simple code based on provided examples:
import scalikejdbc._, SQLInterpolation._
object Test extends App {
Class.forName("org.sqlite.JDBC")
ConnectionPool.singleton("jdbc:sqlite:test.db", null, null)
implicit val session = AutoSession
println(sql"""SELECT * FROM kv WHERE key == 'seq' LIMIT 1""".map(identity).single().apply()))
}
It fails with exception:
Exception in thread "main" java.sql.SQLException: Cannot change read-only flag after establishing a connection. Use SQLiteConfig#setReadOnly and QLiteConfig.createConnection().
at org.sqlite.SQLiteConnection.setReadOnly(SQLiteConnection.java:447)
at org.apache.commons.dbcp.DelegatingConnection.setReadOnly(DelegatingConnection.java:377)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setReadOnly(PoolingDataSource.java:338)
at scalikejdbc.DBConnection$class.readOnlySession(DB.scala:138)
at scalikejdbc.DB.readOnlySession(DB.scala:498)
...
I've tried both scalikejdbc 1.7 and 2.0, error remains. As sqlite driver I use "org.xerial" % "sqlite-jdbc" % "3.7.+".
What can I do to fix the error?
The following will create two separate connections, one for read-only operations and the other for writes.
ConnectionPool.add("mydb", s"jdbc:sqlite:${db.getAbsolutePath}", "", "")
ConnectionPool.add(
"mydb_ro", {
val conf = new SQLiteConfig()
conf.setReadOnly(true)
val source = new SQLiteDataSource(conf)
source.setUrl(s"jdbc:sqlite:${db.getAbsolutePath}")
new DataSourceConnectionPool(source)
}
)
I found that the reason is that you're using "org.xerial" % "sqlite-jdbc" % "3.7.15-M1". This version looks still unstable.
Use "3.7.2" as same as #kawty.
Building on #Synesso's answer, I expanded slightly to be able to get config value from config files and to set connection settings:
import scalikejdbc._
import scalikejdbc.config.TypesafeConfigReader
case class SqlLiteDataSourceConnectionPool(source: DataSource,
override val settings: ConnectionPoolSettings)
extends DataSourceConnectionPool(source)
// read settings for 'default' database
val cpSettings = TypesafeConfigReader.readConnectionPoolSettings()
val JDBCSettings(url, user, password, driver) = TypesafeConfigReader.readJDBCSettings()
// use those to create two connection pools
ConnectionPool.add("db", url, user, password, cpSettings)
ConnectionPool.add(
"db_ro", {
val conf = new SQLiteConfig()
conf.setReadOnly(true)
val source = new SQLiteDataSource(conf)
source.setUrl(url)
SqlLiteDataSourceConnectionPool(source, cpSettings)
}
)
// example using 'NamedDB'
val name: Option[String] = NamedDB("db_ro") readOnly { implicit session =>
sql"select name from users where id = $id".map(rs => rs.string("name")).single.apply()
}
This worked for me with org.xerial/sqlite-jdbc 3.28.0:
String path = ...
SQLiteConfig config = new SQLiteConfig();
config.setReadOnly(true);
return DriverManager.getConnection("jdbc:sqlite:" + path, config.toProperties());
Interestingly, I wrote a different solution on the issue on the xerial repo:
PoolProperties props = new PoolProperties();
props.setDriverClassName("org.sqlite.JDBC");
props.setUrl("jdbc:sqlite:...");
Properties extraProps = new Properties();
extraProps.setProperty("open_mode", SQLiteOpenMode.READONLY.flag + "");
props.setDbProperties(extraProps);
// This line can be left in or removed; it no longer causes a problem
// as long as the open_mode code is present.
props.setDefaultReadOnly(true);
return new DataSource(props);
I don't recall why I needed the second, and was then able to simplify it back to the first one. But if the first doesn't work, you might try the second. It uses a SQLite-specific open_mode flag that then makes it safe (but unnecessary) to use the setDefaultReadOnly call.

Powerbuilder 9- how to use adobe writer instead of Ghostscript for SaveAs()

We have Adobe PDF writer and would like to be able to use this instead of ghostscript. Is the SaveAs() function locked into ghostscript and, if so, how can I use adobe pdf writer to get around this?
I think this could be the solution:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc00844_1150/html/pbug/pbug526.htm
The key change is that you need to create your own printer not using the GhostScript files than the files shipped with Adobe.
I think you should create your Adobe PDF Printer in this way:
http://www.ehow.com/how_5782035_add-adobe-pdf-printer.html
So you should add a local printer with using this file:
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Xtras\AdobePDF". Click the
"AdobePDF.inf"
After this the code should something similar to this:
int li_ret
dw_1.Object.DataWindow.Export.PDF.Method = Distill!
dw_1.Object.DataWindow.Printer = "YourAdobePDFPrinterName"
dw_1.Object.DataWindow.Export.PDF.Distill.CustomPostScript="Yes"
li_ret = dw_1.SaveAs("custom.PDF", PDF!, true)
Of course there could be many other problems with printing. Feel free to ask!
Br.: Gábor
The SaveAs() function is tied to using Ghostscript, to print using Adobe Acrobat, you treat it as a regular printer. Hopefully PB 9 has these functions as this is taken from PB 11.5.
RegistrySet("HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\9.0\AdobePDFOutputFolder", "", ReguLong!, 2)
RegistrySet("HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\9.0\AdobePDFOutputFolder", "2", RegString!, "C:\_APPS")
//Gets the default printer
ls_default = PrintGetPrinter()
//Parses string
ll_pos = Pos(ls_default, "~t")
is_default_printer = Left(ls_default, ll_pos - 1)
//Gets the Printers on the computer
ls_printers = PrintGetPrinters( )
//Finds the Distiller printer
ll_pos = PosA(ls_printers, "Acrobat Distiller")
//Checks for newer version of Distiller
if (ll_pos = 0) then
ll_pos = PosA(ls_printers, "Adobe PDF")
end if
//Gets the location of the Distiller printer
ls_printer = MidA(ls_printers, ll_pos, PosA(ls_printers, ":", ll_pos) - ll_pos + 1)
//Sets our next print ll_job to print to Distiller
PrintSetPrinter(ls_printer)
//Allocates memory for our DS
DS = create DataStore
//Opens Print Job
ll_job = PrintOpen("MyPDF", false)
//Checks for error
if (ll_job > 0) then
//First Datastore to add to the PDF
DS.DataObject = "d_wlcp_view"
DS.SetTransObject(SQLCA)
DS.Retrieve(idt_review_date, ii_site_id)
PrintDataWindow(ll_job, DS)
//You can add more pages to the PDF by printing more DW's or DS's
DS.DataObject = "d_training_view"
DS.SetTransObject(SQLCA)
DS.Retrieve(idt_review_date, ii_site_id)
PrintDataWindow(ll_job, DS)
//Closes the print job
PrintClose(ll_job)
//Sets the default printer back
PrintSetPrinter(ls_default)
//Sometimes the PB function doesn't set the printer back, so you can use
//this VB script to make sure it is set back to the default
//Run('cscript C:\_APPS\HWLCPRR\prnmngr.vbs -t -p "' + is_default_printer + '"')
//Deallocates memory for DS
if (isValid(DS)) then destroy DS
Here is the VB Script.

youtube api upload "Cannot close stream until all bytes are written"

I am using the youtube api to direct upload videos like this:
YouTubeRequestSettings setting = new YouTubeRequestSettings("devpa", key, "user", "pass");
YouTubeRequest req = new YouTubeRequest(setting);
Video ytv = new Video();
ytv.Title = "test video1";
ytv.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
ytv.Keywords = "test, dev";
ytv.Description = "this is a test video";
ytv.YouTubeEntry.Private = true;
ytv.YouTubeEntry.MediaSource = new MediaFileSource(Server.MapPath("PATH"), "video/mp4");
Video createdVideo = req.Upload(ytv);
But every time i get this error:
Cannot close stream until all bytes are written
Even though *i am uploading small videos with different extinctions (flv,mp4 ..etc) *, what is the problem?
Thanks
You need to set timeout. Like ytv.TimeOut = 100000000;
Actually set the instance of
YouTubeRequestSettings.Timeout = [A LARGER NUMBER]
That's the setting you'll want to use.

J2ME, Exception when casting from PemObject to AsymmetricKeyParameter with BouncyCastle

my question for today is about the BouncyCastle encryption Library for J2ME,
I have some code in C# in which I do the following cast:
AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.ReadObject();
this works on the C# end, however when I do it in Java I get an error stating that pubReader doesn't have a ReadObject() method, I changed it to readObject(), still doesn't exist so I went ahead to search for a method that would return an Object type, I only found readPemObject() as follows:
AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.readPemObject();
However... this is when I hit the big problem, as I cannot cast from PemObject to AsymmetricKeyParameter and end up having an error...
here's the majority of the code in question:
PemReader pubReader = new PemReader(new StringReader(pubKey));
AsymmetricKeyParameter nhe = (AsymmetricKeyParameter)pubReader.readPemObject();
Imported teste = new Imported();
PemObject pobj = pubReader.readPemObject();
System.out.println("PemObject: " + pobj);
byte[] output = teste.Encrypt(holyshizzle.getBytes(), nhe);
System.out.println(new String(output));
byte[] revvit = teste.Decrypt(output, (AsymmetricKeyParameter)blah.getPrivate());
System.out.println(new String(revvit));`
PS: The Imported class is where the encrypt/decrypt code is and all of that is working fine (tested it with generated keys), I'm attempting to do this with pre-made encryption keys
Regards,
Gonçalo Vieira
Try replacing
AsymmetricKeyParameter nhe = (AsymmetricKeyParameter)pubReader.readPemObject();
with
AsymmetricKeyParameter nhe = PublicKeyFactory.createKey(pubReader.readPemObject().getContent());

firefox won't convert string to number in flex

I making a web app in Flex using global coordinates
I get the coordinates as strings from a web service then I do something like this:
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This works PERFECT on IE and chrome, from the web server and when debugging locally, but Firefox just works when debugging locally and not from the web server, in the web server cLat and cLong return "NaN".
check it out yourself, it should pop up an alert when you click on a result:
http://mundobuk.com/prueba/mapa/main.html?buscar=oxxo
so I tried using parseFloat(), but it rounds cLat to 28 and cLong to -106 :(
Then I tried separating the decimals form integers, like from my example 28 and 7242100786401 then divide 7242100786401/10000000000000 = 0.7242100786401
having 2 numbers 28 and 0.7242100786401 I add them up
28 + 0.7242100786401 = 28.7242100786401
here is in code form:
var latArr:Array = latStr.split(".");
var longArr:Array = longStr.split(".");
var latDivStr:String = "1";
for (var i:int= 0; i< latArr[1].length; i++){
latDivStr += "0";
}
var longDivStr:String = "1";
for (var j:int = 0; j< longArr[1].length; j++){
longDivStr += "0";
}
var cLat:Number = parseFloat(latArr[0]) + arseFloat(latArr[1])/parseFloat(latDivStr);
var cLong:Number = parseFloat(longArr[0]) - parseFloat(longArr[1])/parseFloat(longDivStr);
again, this way works great everywhere, just not in firefox in the web server >_>
anyone have any ideas? im going crazy whit this #_#
Comma is the separator for many European countries, so it's most likely the regional configuration on either the server or the client.
I have never hear of such an error as The Flash run-time is supposed to make the different browsers and OS's interpret the SWF the same way. I will say that I don't believe you should be using "new" in-front of your Number casting.
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This should be:
var cLat:Number = Number(latStr); //Number is right because its a Floating Point, but remove new.
var cLong:Number = Number(longStr); //Number is right because its a Floating Point, but remove new.
I tested the using the following and saw no rounding take place.
var latStr:String = "28.7242100786401";
var longStr:String = "-106.12635420984";
trace(parseFloat(latStr)); //Outputs: "28.7242100786401";
trace(parseFloat(longStr)); //Outputs: "-106.12635420984";
trace(Number(latStr)); //Outputs: "28.7242100786401";
trace(Number(longStr)); //Outputs: "-106.12635420984";
I do not see why you require this workaround. Also I use firefox as my main browser and your site seems to be working just fine.
Cheers.
I finally found out why its not working, for some reason in firefox instead of reading a dot (.) it reads a comma (,) from the web service (done in vb.net)
locally it reads it as a dot too, not online, so I suppose it has to do something with my IIS server O_o
hope this helps someone out there...

Resources