Open new tab Selenium 3.0 and geckodriver using control T does not work - geckodriver

Using Keys.CTRL + t, is not opening new tab in Selenium 3.0 with gecko driver
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");

once I tried Robot for that, like -
try{
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_T);
}catch (AWTException e){
e.printStackTrace(); // Or do whatever in here
}
I don't really sure in relation of keys in here (VK_CONTROL and VK_T), that's what you'll have to find out, but it worked for me.
P.S.
Probably, you'll have to release keys after.

Related

Access remote database using DataSnap technology in C++ Builder 10.1 Berlin

How to query and get results from remote database using DataSnap technology in C++ Builder 10.1 Berlin ?
I want to build a simple solution having two VCL Forms Applications, like client(1) and server(2), running on two different windows os computers, connected on same local network.
But I cannot accomplish this simple task and this is what I tried to do:
On the server application (2), I use:
TSQLConnection *SQLConnection1;
TSQLQuery *SQLQuery1;
and I will load a SQLite database version 3:
if (SQLConnection1->Params->IndexOf("Database") == -1)
{
SQLConnection1->Params->Add("Database="+Form->DataBaseFile );
}
else
{
SQLConnection1->Params->Values["Database"] = Form->DataBaseFile;
}
try
{
SQLConnection1->Connected = true;
}
catch (EDatabaseError& E)
{
ShowMessage("Exception raised with message" + E.Message);
}
and execute sql query:
try
{
SQLQuery1->SQL->Text = "query from client app(1)";
SQLQuery1->Active = false;
SQLQuery1->ExecSQL();
}
catch (Exception& E)
{
ShowMessage( "SQLite exception raised with message:\n\n" + E.Message);
SQLConnection1->Connected = false;
}
and I need to return SQLQuery1 results back to client app(1)
On the client application I think I should do something like below, but I'm not sure, I don't know how to do this correctly:
TSQLServerMethod *SQLServerMethod1;
SQLServerMethod->SQLConnection = SQLConnection1;
try{
SQLServerMethod.ServerMethodName = "TDSUtilityMethods.echoOutStr";
SQLServerMethod->Params[0]->AsString = "123";
SQLServerMethod->ExecuteMethod();
memoOutput->Text = SQLServerMethod->Params[1]->AsString;
}
finally{
SQLServerMethod->Close();
}
So the purpose is to make a server application(2) which host and execute sql queries from client app(1) which sends the sql query and waits for results. The application(1) which send sql query is a wrapper of chromium client. I tried to achieve all this solution using TIdHTTPServer on sever app(2) and WebSockets from chromium client app(1), and posted a releated question here but implementing WebSocket protocol(encoding/decoding packets) is a bit hard for an amateur developer. And then I found that a easier solution could be using DataSnap technology. I have read about Developing DataSnap Applications, but still not able to build this simple solution, on embarcadero website are described each component, but because I'm amateur developer, I found it confusing and hard to complete a simple task which seems possible and easier to build using DataSnap technology than WebSockets. But now I found hard to implement DataSnap technology, because there is a lot of new things which are confusing without examples.
Please if you know how to do this in C++ Builder 10.1 Berlin, show here a short sample of that.

how to do automated browser testing with Dart?

Is there any headless browser for dart? Or a wrapper for something like selenium? My goal is to use the browser for automated end-user testing for a website i wrote years ago. Now i need to make few changes on the site. Since it contains specific business logic, i would like to write some quick tests for the site without refactoring or modifying it for unit-tests, before i make those changes.
It seems like a fun introduction to get more familiar with dart ecosystem as well.
You can use Chrome or Dartium and drive it with ChromeDriver and the webdriver package
Here is a quick example:
import 'dart:convert';
import 'dart:io';
import 'package:webdriver/io.dart';
main() async {
// Start the ChromeDriver process
Process chromeDriverProcess = await Process
.start('chromedriver', ['--port=4444', '--url-base=wd/hub']);
await for (String browserOut in const LineSplitter()
.bind(UTF8.decoder.bind(chromeDriverProcess.stdout))) {
if (browserOut.contains('Starting ChromeDriver')) {
break;
}
}
// Connect to it with the webdriver package
WebDriver driver = await createDriver(
uri: Uri.parse('http://localhost:4444/wd/hub/'),
desired: Capabilities.chrome);
// Go to your page
await driver.get('http://stackoverflow.com');
//TODO: write your tests
print(await driver.execute('return navigator.userAgent', []));
// Take a simple screenshot
String screenshot = await driver.captureScreenshotAsBase64();
new File('stackoverflow.png').writeAsBytesSync(BASE64.decode(screenshot));
driver.quit();
chromeDriverProcess.kill();
}
It is not totally "headless" but it is easy to make it work on server like Travis-CI with this config:
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
content-shell is a headless browser with Dart support like Dartium
(https://www.dartlang.org/install/mac)
and https://pub.dartlang.org/packages/webdriver can be used for Selenium test.
There is headless support for Chromium work-in-progress. When Dartium is upgraded to use this Chromium version, Dartium should be able to be run headless.
The Dart team is working on incremental JS compilation (DDC - Dart development compiler) which should allow to use Chrome as development browser. The headless mode (when available) can be used directly.
Depending on your use case and requirements, you might also be able to use puppeteer
For example (from the docs), you can take a screenshot of the page
void main() async {
// Start the browser and go to a web page
var browser = await puppeteer.launch();
var page = await browser.newPage();
// Setup the dimensions and user-agent of a particular phone
await page.emulate(puppeteer.devices.pixel2XL);
await page.goto('https://dart.dev', wait: Until.networkIdle);
// Take a screenshot of the page
var screenshot = await page.screenshot();
// Save it to a file
await File('example/_github.png').writeAsBytes(screenshot);
await browser.close();
}
You can also generate a PDF, take a screenshot of a node, interact with the page, evaluate JavaScript, and use the results from your Dart code, and more.

grails 2.4 java 8 and tomcat 7.0.55.2

I am attempting to run a https site using grails 2.4.4 with tomcat plugin :
build ':tomcat:7.0.55.2'
Upon first attempt to launch the app I hit the following issue: issue 648
java.lang.ClassNotFoundException: com.ibm.crypto.tools.KeyTool
When I change the tomcat dependency for tomcat to tomcat 8.0.22 and run app again it succeeds and goes beyond i.e. createSSLCertificate(File keystoreDir) works and although the app does not start up. If I now change it back to tomcat 7.0.55.2 the keys have been generated and the app works.
I guess the question is I was unsure if that fix that Graeme has pointed to only exists in tomcat 8 or is there a later version of tomcat 7 I could use that has a fix for this problem.
Whilst this hack is ok for a development machine, I really need something more concrete for when the app is built via jenkins etc.
To recreate this locally, if I do a
grails clean-all
and try
grails run-app -https
I hit the issue for the very first time until I repeat the above steps again.
Thinking about it Jenkins producing a WAR file may actually be fine, although from a development point of view it still be nice to find a nicer way of making this all work.
I've run into this problem myself aswell. I have tried some other solutions I found on the internet until I stumbled on
https://github.com/grails/grails-profile-repository/pull/14/files
This did the trick for me to solve this issue and run my application with -https
Go to TomcatServer.groovy, and replace:
protected getKeyToolClass() {
try {
Class.forName 'sun.security.tools.KeyTool'
}
catch (ClassNotFoundException e) {
// no try/catch for this one, if neither is foun\d let it fail
Class.forName 'com.ibm.crypto.tools.KeyTool'
}
}
with:
protected Class getKeyToolClass() {
try {
try {
// Sun JDK 8
return Class.forName('sun.security.tools.keytool.Main')
}
catch (ClassNotFoundException e1) {
try {
// Sun pre-JDK 8
return Class.forName('sun.security.tools.KeyTool')
}
catch (ClassNotFoundException e2) {
// no try/catch for this one, if neither is found let it fail
return Class.forName('com.ibm.crypto.tools.KeyTool')
}
}
}
catch (Throwable e) {
return null
}
}

Version 2.0 script causes exception when run under version 3.0

WRT this question -- I got something working by getting the current 'prompt' function as a string and writing a new .ps1 file defining 'prompt'.
In writing the new function, I put the functionality I want to add in a try/catch block, and write the existing prompt functionality into a finally block.
Not at all ideal, but it works in v2.0. When I run it in v3.0, I get an exception:
"Control cannot leave a finally block"
Is there any way to for a script to ask the host for a certain version's behavior?
Thanks for any insights.
Current 'prompt' function consists of:
return " > "
I want to add some functionality to the prompt function, so I write a new temp.ps1 file. I add my functionality in try/catch block, and include the existing in a finally block.
The temp.ps1 looks something like:
function global:prompt {
try {
pushd
}
catch {
$errors[0] | fl * -force
}
finally {
return " > "
}
}
This works as expected in v2, causes the "Control cannot leave..." error in V3.
If you plan to keep using Powershell V3, you cannot have a return statement in your finally block. See Page 6 of Windows Management Framework 3.0 Release notes: (You shouldn't need a return value there anyways)
http://download.microsoft.com/download/5/2/B/52B59966-3009-4F39-A99E-3732717BBE2A/WMF3%200%20Beta%20Release%20Notes.docx

Firefox Driver hangs on creation when using Jenkins node

I have just installed the Selenium Grid plugin for Jenkins and beginning to explore distributing tests with it. I have created a simple test that just opens a browser, gets a url, and then closes the browser. This seems to work for Chrome (on Mac) and IE (on Windows) but for some reason when using Firefox 18.0.2 on Mac, I see the browser window open but the url I'm supposed to load never shows up in the url bar and things hang and I get an error:
WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
It is hanging somewhere in the constructor to create the RemoteDriver. I added a trace statement right after the constructor and the code never gets there.
The weird thing is the test executes just fine if I start up a local Selenium Grid node on the same machine that fails and direct my tests there instead of the Jenkins Selenium Grid hub. So it seems to potentially be an issue with how I set up the Jenkins node but I can't figure out how to troubleshoot this. Any help would be appreciated.
My code is something like this:
WebDriver driver = null;
public Browser(String gridUrl) {
driver = makeFirefox(gridUrl);
driver.get(url);
}
private WebDriver makeFirefox(String gridUrl) {
FirefoxProfile prof = new FirefoxProfile();
prof.setEnableNativeEvents(true);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, prof);
WebDriver driver = null;
try{
driver = new RemoteWebDriver(new URL(gridUrl), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
For anyone who runs into this, I was able to at least temporarily "solve" the problem by downgrading to Firefox 17. Things work fine there, just not Firefox 18.

Resources