Trying to get Protractor's location strategies in Node script (protractor.By) - webdriver

I'm trying to setup protractor in a node script and I would like to get access to the location strategies. However, because I'm doing something stupid I am not seeing them on the protractor object:
var protractor = require('protractor');
//... Wrapping selenium driver
var by = protractor.By;
//console.log(by) returns '{}'
//and protractor.getInstance(); is returning undefined:
How might I get access to the selection strategies (by element, model etc). (I'm writing the script in this manner to work with CucumberJS, so, given the current setup I have I cannot simply run the protractor executable directly).

For anyone who cares to integrate Protractor and CucumberJS, the heuristic should be to execute protractor and have protractor execute cucumber, not the other way around.
My approach was completely wrong: Both protractor and CucumberJS are capable of integrating and executing the other's executable, however, using cucumberJS first would appear to be wrong. Rather I suggest using protractor to Drive the tests. Documentation for protractor integration with CucumberJS is extremely poor and difficult to find. Moreover there are a number of misleading pieces of information.
Right approach
See these example files in the protractor repo which, while not documented to my knowledge (or even acknowledged) provide what would appear to be an adequate means to integrate both tools. To execute it is necessary to have a protractor config setup appropriately
Wrong approach
Problems: Protractor Location strategies don't appear to work. protractor.getInstace() is undefined. protractor.By == {}
Following examples such as this, the implied setup in cucumberJS and similar examples with selenium results in protractor not fully initialising. The effect is that the location strategies appear undefined. There may well be a means to make it work, but after digging through the source-code for days I cannot find it easily.

Related

importance of do_build function in bitbake

I am new to bitbake and i am trying to learn it.
I am going through below link for getting a basic understanding
https://a4z.gitlab.io/docs/BitBake/guide.html
Here either through inheritance or directly i see a do_build is always executed.
this might seem a basic question but your answer would really help me.
I read a line like this "build is the task BitBake runs per default if no other task is specified".
Does it mean build is mandatory in bitbake.Is it like main function in c and c+= codes?
Thanks
When no task is specified on the commandline to bitbake, "build" is assumed. This can be overridden with the BB_DEFAULT_TASK variable to some other task. If a task isn't defined and you try and run it, an error will occur that the task can't be found. As such, a build task isn't absolutely required but you will likely run into errors without it in most common usages.

How to pause a watir cucumber script mid-execution and then resume it?

P.S.: No, I do not want to debug my script. It is pretty awesome.
The problem is the application under test. If I place a few orders, it crashes. So what I want to do is: mid-execution, when I see that the application is crashed, I want to pause the test script, bring the application back up and running, and then resume the test.
I know that this is not the point of time when I should be running the test scripts as the application is not stable enough, but the developers are working on it and hopefully soon enough, they will fix it. I am just curious to know if there is a solution, because I couldn't find one. Of course I could've integrated bringing the application up again when it crashes in my tests, but that is not what I want to do.
My system:
OS: Linux Mint
Tests: Watir (Ruby) + Cucumber on Chrome
I run the tests on linux terminal using cucumber tags.
I just want to know in general if there is any way to pause and resume execution. For example, when I want to stop all the tests, I give the command line interruption Ctrl + C. So is there any such interrupt command to pause and resume?
Okay, since you want a "general" answer, here goes...
Based on your context, you are looking for a "crashed" condition in your project.
My own approach to solving this problem would involve writing a helper method that would look for this condition and, if true, it would "pause". For example...
def pause_if_crashed
sleep 30 if #browser.product_price.nil?
end
Then I would sprinkle this helper method in likely "crash" spots in my other functional methods.
Without more specifics about your needs, this is about as helpful as I can get, I think.

Protractor implicit waiting not working when using grunt-protractor-runner

I am writing e2e Tests for some JS application at the moment. Since I am not a JS developer I was investigating on this theme for a while and ended up with the following setup:
Jasmine2 as testing framework
grunt as "build-tool"
protractor as test runner
jenkins as CI server (already in use for plenty java projects)
Although the application under tests is not written in angular I decided to go for protractor, following a nice guide on howto make protractor run nicely even without angular.
Writing some simple tests and running them locally worked like a charm. In order to implicitly wait for some elements to show up in den DOM I used the following code in my conf.js:
onPrepare: function() {
browser.driver.manage().timeouts().implicitlyWait(5000);
}
All my tests were running as expected and so I decided to go to the next step, i.e. installation in the CI server.
The development team of the aplication I want to tests was already using grunt to build their application so I decided to just hook myself into that. The goal of my new grunt task is to:
assemble the application
start a local webserver running the application
run my protractor test
write some test reports
Finally I accomplished all of the above steps, but I am dealing with a problem now I cannot solve and did not find any help googling it. In order to run the protractor test from grunt I installed the grunt-protractor-runner.
The tests are running, BUT the implicit wait is not working, causing some tests to fail. When I added some explicit waits (browser.sleep(...)) everything is ok again but that is not what I want.
Is there any chance to get implicitly waiting to work when using the grunt-protractor-runner?
UPDATE:
The problem does not have anything to do with the grunt-protractor-runner. When using a different webserver I start up during my taks its working again. To be more precisley: Using the plugin "grunt-contrib-connect" the tests is working using the plugin "grunt-php" the test fails. So I am looking for another php server for grunt now. I will be updating this question.
UPDATE 2:
While looking for some alternatives I considered and finally decided to mock the PHP part of the app.

Selenium tests sometimes fail, sometimes pass

I have created tests using selenium 2, I'm also using the selenium standalone server to run the tests.
The problem is that if I run one test, it works. If I run multiple tests, some of them fail. If I try then to run a failed test, it works.
Could the tests be running on threads?
I've used the NUnit GUI, and TeamCity to run the tests ... both give the same results : different tests fail, run again, other tests fail.
Any thoughts ?
EDIT
The tests shouldn't depend on one another. The database is emptied and repopulated for every test.
I guess the only problem could be that the database is not emptied correctly ... but then if I run the same test multiple times it should also fail.
EDIT2
The tests fail with "element not found".
I'll try and add a "WaitForElement" that retries every few milliseconds and maybe that will fix it.
Without knowing the exact errors that are thrown its hard to say. The normal causes of flakiness tend to be waits are not set to a decent time or the web server can't handle that many requests.
If the DB is on the same machine as the webserver, and why shouldnt it be on a build box, it can be intensive to clear it out.
I would recommend going through each of the errors and making it bullet proof for that and then moving to the next. I know people who run there tests all the time without flakiness so its definitely an environmental thing that can be sorted.
I know I'm a bit late to the party here but are you using a single window to run your tests? I had a similar issue since the site I'm testing has only one page load event so waiting for elements or pausing the test became very dodgy and I had different tests passing each time. Adding a ton of wait times didn't work at all until I just opened a new "clean" browser for each test. Testing does get slower but it worked.

Doh / dijit robot - no mouse actions happening

I wrote an automated test using dijit robot - but in order to be able to use relative paths within our web application, I created an OSGi service for our tests and put the test code in a velocity template. When I try to run the tests, nothing happens. If I use the same script in an html file and access it directly from windows explorer (not via localhost), it works fine. I find that there are many cases that will make the dijit robot tests just not run - has anyone ran into this and found out all the little gotchas to make dijit tests run?
Check out dijit.initRobot(), that might take care of some things for you.
One thing that was screwing up a lot of my tests is described in this blog post - basically the robot was not initializing because I was obscuring a special div that the robot clicks to initialize.
However I have realized that there are still quite a few problems with the doh robot - it just seems very fragile. Often I will have a working test, then add 1 robot command and the test will break. When I remove the line and try it again...well the robot wont run even though it is the exact same code as before.
I've found the best thing to do when writing robot code is to just clear the cache every time and cross your fingers. Good luck.
Problem can be if you trying it with openjdk, run it on oracle java version

Resources