Using Firefox for Play Framework integration tests - firefox

I've started a new Play application
play new todolist
I created project/Build.scala
import sbt._
import Keys._
object ApplicationBuild extends Build {
val appName = "Your application"
val appVersion = "1.0"
val appDependencies = Seq(
"org.seleniumhq.selenium" % "selenium-firefox-driver" % "2.40.0" % "test"
)
}
I also modified test/IntegrationSpec.scala to use Firefox
#RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {
"Application" should {
"work from within a browser" in {
running(TestServer(9000, application = FakeApplication()), FIREFOX) { browser =>
browser.goTo("http://localhost:9000")
browser.pageSource must contain("Your new application is ready.")
}
}
}
}
When I run play test, a Firefox browser starts, but it never goes to a url. The interesting parts from the exception are
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 648: aUrl is undefined
and
[error] WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7057; process output follows:
I've put a gist here with the full stacktrace.
What am I doing wrong? How do I get Firefox to work with Play Framework and actually run a test?

If you still having the problem, I had a similar one and solved it updating the selenium dependency:
libraryDependencies ++= Seq("org.seleniumhq.selenium" % "selenium-java" % "2.43.0")
Hope it helps.

Related

ScalaFx MouseEvent: java.lang.NoSuchFieldError: BACK

What can be the reason for getting this error in run-time (see title) while referring to ScalaFx class, instead if I switch to JavaFx class reference (workaround) things work as expected? With Scala 2.12 and ScalaFx 8.0.192-R14 things were working without JavaFx based workaround. About the environment: Scala 2.13.1, ScalaFx 12.0.2-R18, IntelliJ 2019.3.2, Java 8, Windows 10. Below I am providing the core snippets hopefully able to highlight the issue.
With ScalaFx MouseEvent class reference it seems to generate the exception with me.button:
import scalafx.Includes._
import scalafx.scene.input.{MouseButton, MouseEvent}
...
def flowPaneEvents(flowpane: FlowPane): Unit = {
flowpane.onMouseClicked = (me: MouseEvent) => {
// this statement causes the exception with scalafx
me.button match {
case MouseButton.Primary => println("primary button")
case MouseButton.Secondary => println("secondary button")
case _ =>
}
me.consume()
}
}
Whereas referring to javaFx classes things are working fine. See below:
import scalafx.Includes._
import javafx.scene.{input => jfxsi}
...
def flowPaneEvents(flowpane: FlowPane): Unit = {
flowpane.onMouseClicked = (me: MouseEvent) => {
// this javafx based reference gets things done
me.getButton match {
case jfxsi.MouseButton.PRIMARY => println("primary button")
case jfxsi.MouseButton.SECONDARY => println("secondary button")
case _ =>
}
me.consume()
}
}
What am I missing (I've tried to re-import sbt library-dependencies, but I've not been lucky so far)?
ScalaFX 12.0.2 is to be used with JavaFX 12. If you are using it with Java 8 you will run into strange issues when you have JavaFX 8 is in the path. Use ScalaFX 8 for Java 8. This is clearly stated on the project website: https://github.com/scalafx/scalafx#scalafx-8
Field "BACK" was added in JavaFX 12. See API documentation here:
https://openjfx.io/javadoc/12/javafx.graphics/javafx/scene/input/MouseButton.html#BACK
It is not present in JavaFX 8, so that is the reason for "java.lang.NoSuchFieldError: BACK" - ScalaFX is trying to access field that is not present.

Groovy #CompileStatic and #TypeChecked order, bug or misunderstanding

I started getting a strange failure when compiling a gradle task class. This is the task I created:
package sample
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.gradle.api.artifacts.Dependency
import org.gradle.api.provider.Property
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.bundling.Zip
import sample.internal.DataSourceXmlConfig
#TypeChecked
#CompileStatic
class DataSource extends Zip {
#Internal
final Property<File> warFile = project.objects.property(File.class)
DataSource() {
warFile.convention(project.provider {
def files = project.configurations.getByName('warApp').fileCollection { Dependency d ->
d.name == (archiveFileName.getOrElse("") - (~/\.[^.]+$/))
}
files.empty ? null : files.first()
})
}
/**
* This function is used to specify the location of data-sources.xml
* and injects it into the archive
* #param dsConf The configuration object used to specify the location of the
* file as well as any extra variables which should be injected into the file
*/
#Input
void dataSourceXml(#DelegatesTo(DataSourceXmlConfig) Closure dsConf) {
filesToUpdate {
DataSourceXmlConfig ds = new DataSourceXmlConfig()
dsConf.delegate = ds
dsConf.resolveStrategy = Closure.DELEGATE_FIRST
dsConf.call()
exclude('**/WEB-INF/classes/data-sources.xml')
from(ds.source) {
if (ds.expansions) {
expand(ds.expansions)
}
into('WEB-INF/classes/')
rename { 'data-sources.xml' }
}
}
}
private def filesToUpdate(#DelegatesTo(AbstractCopyTask) Closure action) {
action.delegate = this
action.resolveStrategy = Closure.DELEGATE_FIRST
if (warFile.isPresent()) {
from(project.zipTree(warFile)) {
action.call()
}
}
}
}
When groovy compiles this class, I get the following error:
Execution failed for task ':buildSrc:compileGroovy'.
BUG! exception in phase 'class generation' in source unit '/tmp/bus-server/buildSrc/src/main/groovy/sample/DataSource.groovy'
At line 28 column 28 On receiver: archiveFileName.getOrElse() with
message: minus and arguments: .[^.]+$ This method should not have
been called. Please try to create a simple example reproducing this
error and file a bug report at
https://issues.apache.org/jira/browse/GROOVY
Gradle version: 5.6
Groovy version: localGroovy() = 2.5.4
tl;dr, is this a bug or am I missing something about how these annotations work?
The first thing I tried to do was to remove either one of #TypeChecked and #CompileStatic annotations to see if the error goes away.
This actually fixed the problem right away. Compiling the source with either annotations added was successful, but fails when both are present.
I read some questions and answers regarding the use of both annotations, but none of them seemed to suggest that one cannot use both at the same time.
Finally, I tried switching the order of the annotations to see if that helps and to my surprise, it worked! No compilation errors!
This works:
#CompileStatic
#TypeChecked
class DataSource extends Zip { ... }
At this point, I guess my question would be, is this a bug or is there something I am not understanding about the use of both of these annotations? I'm leaning more towards it being a bug just because of the fact that the order made the error message go away.

Updating a framework in xcode

I am developing a framework.. I managed to build a 1.0 version but Now I have added a new class to the framework but this class is not visible to everything else it seems.. What are the steps to "recompile" or fix this problem?
This could be down to lots of things, but I was in a similar situation yesterday and the cause was my failure to put all the relevant files in the Compile Sources table (found by selecting your framework in the Targets browser, and navigating to the Build Phases section):
If you're using Swift, and you're trying to access the classes in your framework from some other target/framework, you also need to make sure you've marked the classes you're trying to access as public (they're internal by default).
// Mark class as public so it's available to other frameworks
public class Logger {
// Can only access this from this file
private var log: [LogEntry] = []
// Only classes in this framework can access this
var liveLog: LogEntryPriority? = .Info // Can only get at this
// Can access this from anywhere
public func getReady(logLevel: LogEntryPriority, errorsAreFatal: Bool) {
log = []
liveLog = logLevel
self.errorsAreFatal = errorsAreFatal
}
}

How to Determine an mxmlc-compiled SWF File Was Built in Debug or Release Mode

First of all, I'm NOT talking about if the player is a debugger or not. (EDIT: it IS actually related to the debugger player)
I use mxmlc to compile a very simple swf file with -debug=false:
mac-108:tmp admin$ "/Applications/Adobe Flash Builder 4.7/sdks/4.6.0/bin/mxmlc" +configname flex -debug=true -static-link-runtime-shared-libraries=true Main.as
Loading configuration file /Applications/Adobe Flash Builder 4.7/sdks/4.6.0/frameworks/flex-config.xml
/Users/admin/tmp/Main.swf (987 bytes)
mac-108:tmp admin$
The Main.as:
package {
import flash.display.MovieClip;
import flash.text.*;
public class Main extends MovieClip {
public function Main() {
// Reference: http://stackoverflow.com/questions/185477/determine-if-swf-is-in-a-debug-player-or-mode
var st:String = new Error().getStackTrace();
var isDebugBuild:Boolean = (st && st.search(/:[0-9]+]$/m) > -1);
var my_st:String = "st: " + (st == null ? 'Null' : st);
var my_DR:String = isDebugBuild?"Debug":"Release";
var obj:TextField = new TextField();
obj.text = my_st + "\n" + my_DR;
this.addChild(obj);
}
}
}
Then I open Main.swf in my Chrome browser, but I see:
st:Null
Release
Which is so weird that, apparently, I have set -debug=true, why does NOT the popular method to determine if an swf is in Debug or Release work.
However, if I move my code to the Flash Builder 4.7, it will give me the Debug output (instead of Release).
It turns out that when the SWF is built in Debug mode, in order to test if it's in debug mode, the Flash Player must also be a debugger using Capabilities.isDebugger.

Groovy retrieve file version property (Windows)

Could you please help me to retrieve file version property from Groovy script (in Windows platform)?
I mean the Version property available in Windows (7) in Details tab of file Properties window opened by right-click on file name.
I found to do it with WSH only.
Thanks In Advance!
First I tried to find a solution with and "More New I/O APIs for the Java™ Platform" (NIO.2) but didn't succeed. When I looked closer at your WSH-example I realized it is COM scripting.
So there are 2 possiblities to solve this:
Com4j
Java Native Access (JNA)
An example for accessing Word from Java can be found here.
Update
I tried to solve your problem, but run into an exception within the Namespace-function:
#Grab(group='net.java.dev.jna', module='platform', version='3.5.2')
import com.sun.jna.platform.win32.COM.COMException
import com.sun.jna.platform.win32.COM.COMObject
import com.sun.jna.platform.win32.OleAuto;
import com.sun.jna.platform.win32.Variant;
import com.sun.jna.platform.win32.Variant.VARIANT;
import com.sun.jna.platform.win32.WTypes.BSTR;
import com.sun.jna.platform.win32.WinNT.HRESULT;
public class Shell extends COMObject {
public Shell() throws COMException {
super("Shell.Application", false);
}
public HRESULT Namespace(String dir) throws COMException
{
def bstrDir = OleAuto.INSTANCE.SysAllocString(dir)
def varDir = new VARIANT(bstrDir)
def result = new VARIANT.ByReference()
HRESULT hr = oleMethod(OleAuto.DISPATCH_METHOD, result, this.iDispatch, "Namespace", varDir);
}
}
def shell = new Shell()
shell.Namespace("C:\\Temp")

Resources