Protractor Fails on Build Server - ElementNotVisibleError - angularjs

All my angular e2e tests using protractor with cucumber are running smooth and fine on my machine. But as soon as I run the tests on the build server, I get an error
ElementNotVisibleError: element not visible
Session info: chrome=51.0.2704.84
Driver info: chromedriver=2.21.371459
platform=Windows NT 6.1 SP1 x86_64
In the beginning, I thought this has something to do with timing, some asynchronous stuff that is happening but after hours of debugging I can finally reproduce the bug even on my local machine.
Minimizing the window is not enough but if I quickly drag the mouse to make the window as small as possible, I get this error. So it is just a matter of "window size".
Thus the error message is quite ok, but how are protractor meant to
run on a build server?
And why are some tests passing? Protractor seems to "see" something on the build server, thus
I tried
browser.driver.manage().window().maximize();
I tried
browser.manage().window().setSize(1920, 1200);
and I tried to change my code as suggested here and I tried a lot of more (hopeless) things. Nothing worked.
My big question now: How can I run a protractor test in a stable fashion on a build server (in my case TFS) when there is a rightmost button I want to click on some page?
Short code sample:
browser.get(browser.baseUrl + '#/somePage').then...
element(by.id(buttonId)).click();
Thank you!
UPDATE:
The main reason for my problems was the fact that the screen resolution while running the test on the build server had a width of 1024 and thus setSize(1920, 1200) failed. For that reason I now added an output of the current resoltuion in the onPrepare function, so that I will get a hint in the future:
onPrepare: function () {
browser.executeScript('return { height: screen.availHeight, width: screen.availWidth, top: screen.availTop, left: screen.availLeft};').then(function (result) {
console.log("Screen resolution: ");
console.log(result);
});
browser.manage().window().setSize(1920, 1200);
Of course this could be extended a little bit to throw an exception or something like this.

Sometimes, we need to bring the desired element into view in order to avoid "Element not visible" error. We can do that in two general ways:
use "browser actions":
var elm = element(by.id("buttonid"));
browser.actions().mouseMove(elm).click().perform()
scroll into view:
var elm = element(by.id("buttonid"));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
Also linking this answer that has a nice set of things you can try to tackle the problem.

Related

How to Execute (Vector) Storage.getInstance().readObject(filePath); in Java 8 Swing Package

Windows 10 Pro
Latest Simulator
Java Swing Project
I would like to execute "Vector a1 = (Vector) Storage.getInstance().readObject(filePath);"
In a Java Swing Application running on Windows 10 platform, I tried import CodenameOne.jar in Swing package, however when executing above code, get null pointer exception in Storage.getInstance()
Is there a way to execute this in Swing?
Thoughts?
Best Regards.
Thanks, I did not init the Display, however "Display.init(Object m)" requires an Object Argument and the Init method is deprecated.
Can you please provide me the codenameone Display dependencies?
And perhaps a java Swing snippet of code to initialize Display in order to execute Storage.getInstance().readObject(filePath)
Thoughts?
Best Regards
Thanks, Passing init(working directory) solved the Exception thrown.
Here is the Code snippet used to allow me to execute:
Storage.getInstance().readObject(filePath).
String filePath = incSrv.Pwd();// gets working directory
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Display.init(filePath);
String fileName = "A1-MMA.properties";
Vector a1 = (Vector) Storage.getInstance().readObject(filePath);
}
});
} catch (Exception e) {
}
And it does appear to work,
However I am left with a blacked out form that appears modal.
How can I avoid this or dispose it?.
FYI: What I am creating here is a work around for serializing Vector in Codenameone. I Save Vector to file using "Storage.getInstance().writeObject(Path, Vector)"
I convert the file to bytes and write it to the Swing Server VIA socket.
Using Storage.getInstance().readObject(file) on the Swing Server I have deserialize the object into the Vector from my app.
This appears to work well and is more efficient than the current method I use to deliver complex Vectors from the app to the Swing Server.
Can you please let me know if you see a red flag with this workaround?
Like The ability to Storage.getInstance().readObject(file) on the Swing Server may go away?
This method will save a lot of time in movind Vector data to and from the App/Server.
Thoughts Best Regards
Storage.getInstance().readObject(file) // (A1ServiceSrv.java:571)
Caused this Exception:
java.lang.NullPointerException
at com.codename1.io.Storage.init(Storage.java:89)
at com.codename1.io.Storage.getInstance(Storage.java:112)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:571)
Regards
12/11/2021:
Thanks Shai,
I am including in my classpath CodenameOne.jar with update date of 12/11/2021 after CN1 refresh.
Getting Same null pointer exception.
Passing in Path "C:\Src1\A1-Arms\A1-Server\A1-MMA.properties" (Absolute Path)
Also Tried "A1-MMA.properties", however I don't think Codenameone knows where my home path is since we are not initializing it as we did with
Display.init("Current Working Directory where files reside");
This is the Fresh Stack Trace w/o calling Display.init (12-20-2021)
java.lang.NullPointerException at
com.codename1.ui.Display.getResourceAsStream(Display.java:3086)
at com.codename1.io.Log.print(Log.java:327)
at com.codename1.io.Log.logThrowable(Log.java:299)
at com.codename1.io.Log.e(Log.java:285)
at com.codename1.io.Storage.readObject(Storage.java:271)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:596)
vector = (Vector) Storage.getInstance().readObject(filePath); // (A1ServiceSrv.java:596)
This is hopefully fixed by this commit: https://github.com/codenameone/CodenameOne/commit/72bf283bdaaefe5207bb9fd6787578e3ef61522c if not let me know with a fresh stack

Jmeter WebDriverSampler fail with Chromedriver headless

I have some tests with WebDriverSampler in Jmeter that work correctly with chromedriver. It is a selenium script that opens a web page and checks that it contains a series of elements. Everything works right until I've tried with the chromedriver headless option.
In this case I get the exception "Expected condition failed: waiting for presence of element located by: By.xpath: ..." as if that element did not exist yet to be loaded. I do not know what can happen, because if I stop using the headless option, if everything works correctly and find the element that really exists.
This is an example of code used(it works without the headless option):
var wait = new support_ui.WebDriverWait(WDS.browser, 30);
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.get('http://mi-app/');
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento_existente')));
WDS.log.info('OK')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail');
WDS.log.error(e.message)
}
try{
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath('/ruta_de elemento2_existente')));
WDS.log.info('OK2')
}catch(e){
WDS.sampleResult.setSuccessful(false);
WDS.sampleResult.setResponseMessage('Fail2');
WDS.log.error(e.message)
}
WDS.sampleResult.sampleEnd();
I hope someone can help me with this problem, because I need to use the headless option. Thank you very much for your time.
You can print the page source to jmeter.log file by using the following function:
WDS.log.info(WDS.browser.getPageSource())
Or even save it into a separate file like:
org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File('test.html'), WDS.browser.getPageSource())
Or take screenshot on failure like:
WDS.browser.getScreenshotAs(org.openqa.selenium.OutputType.FILE).renameTo(new java.io.File('test.png'))
Check out The WebDriver Sampler: Your Top 10 Questions Answered article for more information.
Also be aware that if the machine where you run your Selenium tests doesn't have GUI you can still normally launch browsers using i.e. Xvfb on Linux or under Local System account on Windows

How to have a Selenium test locate elements generated by Angular?

I'm currently taking the angular tutorial using Wisdom framework as back end. As a consequence, I run end-to-end tests using Fluentlenium, as the wisdom framework doc states.
My test for step 3, although dead simple, doesn't pass.
Full test can be found at github : Step03IsImplementedIT
However, here is the offending extract (around lines 30)
#Test
public void canTestPageCorrectly() {
if (getDriver() instanceof HtmlUnitDriver) {
HtmlUnitDriver driver = (HtmlUnitDriver) getDriver();
if(!driver.isJavascriptEnabled()) {
driver.setJavascriptEnabled(true);
}
Assert.assertTrue("Javascript should be enabled for Angular to work !", driver.isJavascriptEnabled());
}
goTo(GoogleShopController.LIST);
// Et on charge la liste des téléphones
FluentWebElement phones = findFirst(".phones");
assertThat(phones).isDisplayed();
FluentList<FluentWebElement> items = find(".phone");
assertThat(items).hasSize(3); // <-- this is the assert that fails
}
Failure message :
canTestPageCorrectly(org.ndx.wisdom.tutorial.angular.Step03IsImplementedIT) Time elapsed: 2.924 sec <<< FAILURE!
java.lang.AssertionError: Expected size: 3. Actual size: 1.
at org.fluentlenium.assertj.custom.FluentListAssert.hasSize(FluentListAssert.java:60)
at org.ndx.wisdom.tutorial.angular.Step03IsImplementedIT.canTestPageCorrectly(Step03IsImplementedIT.java:33)
From that failure, I guess the angular controllers weren't loaded.
How can I make sure they are ? And how can I have a working test ?
Turned out the error wasn't the expected one ... Well, it was, but in a hidden fashion.
HtmlUnitDriver, as one may be aware, is a pure Java implementation of a browser and, as such, has some limitations.
One of its limitation is Javascript interpretation, which seems to go awfully bad with angular ....
To make long things short, the simplest way to fix that is to replace the default driver with firefox one which implies
setting fluentlenium.browser to firefox
make sure driver loads correctly (since firefox.exe should be on path when trying to use its driver) by adding a small assert at the beginning of the test
Final test is then
assertThat(getDriver()).isInstanceOf(FirefoxDriver.class);
goTo(GoogleShopController.LIST);
FluentList<FluentWebElement> items = find("li");
FluentLeniumAssertions.assertThat(items).hasSize(3);
fill("input").with("nexus");
await();
items = find(".phone");
FluentLeniumAssertions.assertThat(items).hasSize(1);
fill("input").with("motorola");
await();
items = find(".phone");
FluentLeniumAssertions.assertThat(items).hasSize(2);

Visual Studio 2012 - Debugger Jumps around randomly

I've been having this issue for a while now an I just cant work past it anymore. I use to just recreate the project but now that solution no longer works for me either and i've had no luck with google at all.
I have a silverlight 5 website with a WCF service. Basically what happens is I'll have a piece of code i need to debug e.g.
using (var connection = new SqlConnection(AccessCardConnection))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "GetAccessCardTimes";
command.CommandTimeout = 300;
command.Parameters.AddWithValue("#EmployeeName", fullName);
command.Parameters.AddWithValue("#FirstDate", firstDate);
command.Parameters.AddWithValue("#LastDate", lastDate);
var accessCardReader = command.ExecuteReader();
while (accessCardReader.Read())
{
var time = TimeSpan.Parse(accessCardReader["TotalOnSiteTime"].ToString());
duration += time;
}
return (duration.TotalHours);
}
However once the first break point hits its anybodies guess which line it will jump to.. It doesnt follow any kind of logical order it, if i set a break point on connection.Open() for example it may jump back into the connection intialization then back down again and jump any which way it pleases, up, down, stay on the same line etc. Jumping in and out of methods as it seems to have no regard for what its doing.
None of the solutions I've found online have helped:
Why do my debugger randomly jump out of debug mode? (Fix is for visual studio 2008)
Visual Studio 2010 Debugger jumps around (Deleting the /bin and /obj files to regenerate the symbols didnt help)
Please can someone give me a hint as to what it may be I cant work like this :(
Thanks for your assistance!
Sounds like you have multiple calls hitting the service. WCF spawns new worker threads for each request so what you are seeing is the debugger "jumping" from thread to thread.

Can Google App Engine's ImagesServiceFactory.getImagesService() be used in unit tests?

I managed to get the code snippet below to run successfully in the development server, re-sizing image to 300x300 pixels as part of a web request.
However, I can't seem to run them in unit tests.
byte[] data = loadMyData();
OutputSettings format = new OutputSettings(ImagesService.OutputEncoding.JPEG);
Image resized = getImagesService().applyTransform(makeResize(300, 300, 0, 0), data, format);
The code above is throwing this exception in unit tests:
java.lang.IllegalArgumentException: Failed to read image
at com.google.appengine.api.images.ImagesServiceImpl.convertApplicationException(ImagesServiceImpl.java:333)
at com.google.appengine.api.images.ImagesServiceImpl.applyTransform(ImagesServiceImpl.java:86)
at com.google.appengine.api.images.ImagesServiceImpl.applyTransform(ImagesServiceImpl.java:63)
Adding "LocalImagesServiceTestConfig" to the LocalServiceTestHelper does not make any difference.
Hope someone can confirm if we can actually use the getImagesService() to resize images in (Java) unit test.
I might be missing something here, but couldn't you just have used the get_serving_url to make your resize? It's available for Java imagesService.getServingUrl(blob)
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl%28com.google.appengine.api.blobstore.BlobKey,%20int,%20boolean%29
Regards,
Niklas

Resources