issue to run behat/selenium with browser without closing it immediately - javascript

I am trying to run the behat/selenium with Chrome browser by running the following feature scenario, and I want to hold the browser screen without closing the Chrome browser immediately. I keep getting the following error on implementing the step definition iWaitForSeconds but I did it already. Below are all the code, could you please help to see what did I do wrong? Thanks so much!!!!
2 scenarios (2 undefined)
10 steps (8 passed, 2 undefined)
0m3.896s
You can implement step definitions for undefined steps with these snippets:
/**
* #Given /^I wait for "([^"]*)" seconds$/
*/
public function iWaitForSeconds($arg1)
{
throw new PendingException();
}
/behat_sample/features/search.feature
# features/search.feature
Feature: Search
In order to see a word definition
As a website user
I need to be able to search for a word
#javascript
Scenario: Searching for a page that does exist
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Behavior Driven Development"
And I press "searchButton"
Then I should see "agile software development"
And I wait for "60" seconds
/behat_sample/behat.yml
#behat.yml
default:
paths:
features: features
bootstrap: '/behat_sample/features/bootstrap'
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://en.wikipedia.org/'
goutte: ~
selenium2: ~
browser_name: chrome
/behat_sample/features/bootstrap/FeatureContext.php
namespace bootstrap;
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
/**
* Initializes context.
* Every scenario gets it's own context object.
*
* #param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
// Initialize your context here
}
/**
* #Given /^I wait for (\d+) seconds$/
*/
public function iWaitForSeconds($seconds)
{
$this->getSession()->wait($seconds*1000);
throw new PendingException();
}

Seems like you set wrong path in bootstrap config key.
It looks for /behat_sample/features/bootstrap instead of your_current_base_behat_dir/features/bootstrap
Try the following:
bootstrap: '%paths.base%/features/bootstrap'
where %paths.base% - thats a where behat root located, from where you start running behat

As I see in the code you need to remove the throw new PendingException() from /^I wait for (\d+) seconds$/ step implementation.
If the wait is done then it should continue not to throw exception.

Related

Vs Code Extension API how to get setting's from remote container?

In a devcontainer, vscode settings can optionally be added to the .devcontainer/devcontainer.json file instead of settings.json.
// devcontainer.json
{
"name": "myapp",
"customizations": {
"vscode": {
"settings": {
"myextension.exclude": [
"**/.git*",
"**/node_modules",
]
},
}
}
}
How can I access these values from the extension API? I know I can get the workspace settings with:
let setting = vscode.workspace.getConfiguration('myextension.exclude');
I've been unable to locate any documentation on dealing with extensions in remote containers.
When looking at the Settings UI, remote containers show up as a separate tab from workspace/user.
The vscode.workspace.getConfiguration API returns a WorkspaceConfiguration, which merges the information from different levels, according to the documentation:
/**
* Represents the configuration. It is a merged view of
*
* - *Default Settings*
* - *Global (User) Settings*
* - *Workspace settings*
* - *Workspace Folder settings* - From one of the {#link workspace.workspaceFolders Workspace Folders} under which requested resource belongs to.
* - *Language settings* - Settings defined under requested language.
*
* The *effective* value (returned by {#linkcode WorkspaceConfiguration.get get}) is computed by overriding or merging the values in the following order:
*
* 1. `defaultValue` (if defined in `package.json` otherwise derived from the value's type)
* 1. `globalValue` (if defined)
* 1. `workspaceValue` (if defined)
* 1. `workspaceFolderValue` (if defined)
* 1. `defaultLanguageValue` (if defined)
* 1. `globalLanguageValue` (if defined)
* 1. `workspaceLanguageValue` (if defined)
* 1. `workspaceFolderLanguageValue` (if defined)
*
* **Note:** Only `object` value types are merged and all other value types are overridden.
...
It doesn't say anything about remotes, but I guess that the setting defined in devcontainer.json is equivalent to Workspace Folder settings.
But your code has a small mistake. You must use dotted notation while dealing with settings. So, in fact, the source code should be:
let setting = vscode.workspace.getConfiguration('myextension').get('exclude');
Just a side note, if you need to load some specific level / view of your setting, you should use the inspect method instead of get, but I don't think this is your case.
Hope this helps

Javascript Dot-Syntax function disappears in listen callback

I'm trying to update Annotorious (https://annotorious.github.io/#) to the latest version of Closure / Javascript.
When I compile it with "SIMPLE" optimizations, dot-syntax functions seem to disappear when goog.events.listen callbacks are invoked. Here's an example:
Here's the "main":
goog.provide('annotorious.Annotorious');
...
/**
* The main entrypoint to the application. The Annotorious class is instantiated exactly once,
* and added to the global window object as 'window.anno'. It exposes the external JavaScript API
* and internally manages the 'modules'. (Each module is responsible for one particular media
* type - image, OpenLayers, etc.)
* #constructor
*/
annotorious.Annotorious = function() {
/** #private **/
this._isInitialized = false;
/** #private **/
this._modules = [ new annotorious.mediatypes.image.ImageModule() ];
...
In another file (they're all compiled together), we have this:
goog.provide('annotorious.Annotation');
goog.require('annotorious.shape');
/**
* A 'domain class' implementation of the external annotation interface.
* #param {string} src the source URL of the annotated object
* #param {string} text the annotation text
* #param {annotorious.shape.Shape} shape the annotated fragment shape
* #constructor
*/
annotorious.Annotation = function(src, text, shape) {
this.src = src;
this.text = text;
this.shapes = [ shape ];
this['context'] = document.URL; // Prevents dead code removal
}
So we start up the code, and at some point we end in the editor for the annotation, listening for a "Save" button:
goog.provide('annotorious.Editor');
....
/**
* Annotation edit form.
* #param {Object} annotator reference to the annotator
* #constructor
*/
annotorious.Editor = function(annotator) {
this.element = goog.soy.renderAsElement(annotorious.templates.editform);
....
/** #private **/
//this._btnSave = goog.dom.query('.annotorious-editor-button-save', this.element)[0];
this._btnSave = this.element.querySelector('.annotorious-editor-button-save');
...
goog.events.listen(this._btnSave, goog.events.EventType.CLICK, function(event) {
event.preventDefault();
var annotation = self.getAnnotation();
annotator.addAnnotation(annotation);
annotator.stopSelection();
if (self._original_annotation)
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation, annotator.getItem());
else
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation, annotator.getItem());
self.close();
});
If I put a breakpoint at "goog.events.listen(this._btnSave...", and type "annotorious.Annotation", I get what I expect:
In fact, it has all kinds of methods:
Then I let the code go, and break in the listener (event.preventDefault();, etc, above):
Now, all the dot-syntax methods are gone.
This of course causes crashes later on.
All of these files are compiled together.
This happens for all callbacks - 'load' events, other ux callbacks, etc.
This must have worked in prior versions of Closure / JS.
What could be causing this?
Thanks!
Ok, I was able to resolve the problem by adding "--assume_function_wrapper" to the closure compiler command line.
Previously, I was compiling the package using Plovr. However, since Plovr hasn't been updated in a long time, I switched to using the closure compiler natively.
Apparently either Plovr provided '--assume_function_wrapper' internally or the version of the compiler Plovr used didn't break the functions as described.
As #john suggests above I'll bet '--assume_function_wrapper' keeps goog.provide from "destroying" namespaces by re-declaring them.

JSDoc for function parameter properties + WebStorm

What is the correct JSDdoc declaration for company being a String in the code below?
fetch('https://api.github.com/users/mdo').then(res => res.json()).then(res => {
console.log(res.company);
});
I use WebStorm and it understandably underscores company as an Unresolved variable:
if I add
/** #namespace bogus.company **/
anywhere in the file, WebStorm is happy, but that doesn't make sense:
Is this a bug in WebStorm, or am I missing something about how JSDoc declarations are supposed to work?
Is JSDoc even supposed to be used for this use case?
If you check the inspection for unresolved javascript variable there is a Report undeclared properties as error option that you could uncheck.
I like to do something like this:
/**
* #param {Object} res
* #property {String} company
*/
function myOutput(res) {
console.log(res.company);
}
fetch('https://api.github.com/users/mdo')
.then(myToJson)
.then(myOutput);
But for small anonymous functions I wouldn't even bother. It's a weak warning so turn the inspection off or learn to live with it, I'd say. It's possible to cram in /** #param {*} something */ in anonymous functions as well, but often it only serves to reduce readability.
Another option is to make a dummy file soomething.js somewhere under your content-root with an anonymous function like:
(() => {
return {
"github-users-response" : {
"company" : "sample"
}
}
});
And now webstorm will figure that company actually is defined in your other files. You can even put it in a different content-root if you want to keep it separate from your project.

How to run V8 evaluation multiple times?

Maybe it is stupid question (I am newbie to C++, just wanted to use it as library for android), but I am not able to run evaluation of some JS multiple times.
I have started with "hello world" tutorial. But then I have wanted simple thing, re-run main (just wrap content of tutorial code into function and run it twice in newly empty main.
This is what I got:
#
# Fatal error in ../src/isolate.cc, line 1868
# Check failed: thread_data_table_.
#
==== C stack trace ===============================
1: 0xa890b9
2: 0x6a22fc
3: 0x42694f
4: 0x405f66
5: 0x405ec7
6: __libc_start_main
7: 0x405dc9
Illegal instruction (core dumped)
This cames after creating new isolate
Isolate* isolate = Isolate::New(create_params);
Well, what I should do? Am I using wrong construct or so? Should I close/delete/clear something more?
In bigger view I just want to do evaluate function, that can be triggered multiple times, and beside that also run multiple js snipets in same context (how to split this function?).
Any idea?
UPDATE:
Ok, lets say that the main can be split into three logical parts:
init
int main(int argc, char* argv[]) {
// Initialize V8.
V8::InitializeICU();
V8::InitializeExternalStartupData(argv[0]);
Platform* platform = platform::CreateDefaultPlatform();
V8::InitializePlatform(platform);
V8::Initialize();
// Create a new Isolate and make it the current one.
ArrayBufferAllocator allocator;
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &allocator;
evaluation
Isolate* isolate = Isolate::New(create_params);
{
Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<String> source =
String::NewFromUtf8(isolate, "'Hello' + ', World!'",
NewStringType::kNormal).ToLocalChecked();
// Compile the source code.
Local<Script> script = Script::Compile(context, source).ToLocalChecked();
// Run the script to get the result.
Local<Value> result = script->Run(context).ToLocalChecked();
// Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result);
printf("%s\n", *utf8);
}
isolate->Dispose();
and clean
// Dispose and tear down V8.
V8::Dispose();
V8::ShutdownPlatform();
delete platform;
return 0;
Now as I said before if I run main consists of init->evaluation->clean twice, that mean init->evaluation->clean->init->evaluation->clean, then the error occurs. I have figured out, that if I extract evaluation part into separate function I can run it multiple times e.g. as init->(evaluation){2}->clean
Is that how should it work? Next step is to divide this main into tree separate function that mean I have to have static member with platform? Could it cause leak somehow?
NOTE: that I want to run it from android, that mean e.g. click in UI, propagate js source to C via JNI and then call c++ V8, which is already initialized or not. hm?
Prefered way is to have "blackbox", but if I have to hold platform, so be it. It maybe could be also faster without re-initialization of V8, right?
UPDATE 2:
Well, still have problems with splitting evaluation part to achieve multiple runs in same isolate/context.
I have splitted it after creating context with stored isolate and context, but with no luck. When in second part try to create source string it fails, probably because of using stored isolate (something with isolate scope I guess).
:(
My assumption as I introduced in UPDATE1 was correct. That part works well.
According to UPDATE2 I have splitted evaluation part into two.
First for initialize isolate and context:
mIsolate = Isolate::New(mCreate_params);
Isolate::Scope isolate_scope(mIsolate);
{
// Create a stack-allocated handle scope.
HandleScope handle_scope(mIsolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(mIsolate);
// Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::NewFromUtf8(mIsolate, "print"), v8::FunctionTemplate::New(mIsolate, Print));
// Create a new context.
mContext = Context::New(mIsolate, NULL, global);
Persistent<Context, CopyablePersistentTraits<Context>> persistent(mIsolate, mContext);
mContext_persistent = persistent;
}
and second that will run js in same context:
Isolate::Scope isolate_scope(mIsolate);
{
HandleScope handle_scope(mIsolate);
mContext = Local<Context>::New(mIsolate, mContext_persistent);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(mContext);
{
// Create a string containing the JavaScript source code.
Local<String> source =
String::NewFromUtf8(mIsolate, js_source, NewStringType::kNormal).ToLocalChecked();
// Compile the source code.
Local<Script> script = Script::Compile(mContext, source).ToLocalChecked();
TryCatch trycatch(mIsolate);
// Run the script to get the result.
v8::Local<v8::Value> result;
if(!script->Run(mContext).ToLocal(&result)){
v8::String::Utf8Value exception_str(trycatch.Exception());
dprint(*exception_str);
}else{
if(!result->IsUndefined()){
String::Utf8Value utf8(result);
dprint(*utf8);
}
}
}
}
Well the code works very well on linux, but I still have some issues when I try to run first part for the second time (create new context) on android:
A/art: art/runtime/thread.cc:986] pthread_getschedparam failed for DumpState: No such process
A/art: art/runtime/base/mutex.cc:485] Unexpected state_ 0 in unlock for logging lock
But that's another question I guess. Peace.
Did you initialize v8 more than once?
v8::V8::Initialize() this method should be called once per process.
deep into project source file "v8/src/v8.cc", you will find the prove
bool V8::Initialize() {
InitializeOncePerProcess();
return true;
}

Change content dynamically when my module cron runs

I have a module named my_module and it uses for running cron. I am using hook_cron() to run cron in my module. I want to change the value of a javascript veriable when cron runs. This javascript variable has already present in the footer. I am using drupal 7. Can any one help me to write codes for this?
This code can get you started.
/**
* Implementation of hook_cron()
*/
function [YOUR_MODULE]_cron() {
variable_set('YOUR_VARIABLE', 'change this value to your liking');
}
/**
* Implementation of hook_init()
*/
function [YOUR_MODULE]_init() {
$yourVariable = variable_get('YOUR_VARIABLE', '');
drupal_add_js(array('YOUR_VARIABLE' => $yourVariable), 'setting');
}
Then in your javascript:
var myVar = Drupal.settings.YOUR_VARIABLE;
Docs:
hook_init()
hook_cron()
variable_get()
variable_set()

Categories