David Borchgrevink

Ranch Hand
+ Follow
since Feb 08, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
12
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Borchgrevink

Jeanne Boyarsky wrote:David,
First of all, I've given you a cow for asking such a great question. It's clear, interesting and contains all the relevant information.



Thanks!

If I'm understanding the data you want to externalize right, I don't think you need the Parameterized Test Case pattern here. I recommend reading up on it anyway though. It's a good tool to have in your tool box.



So I know Cucumber can do the data table thing using Examples in the feature files, which is nice, but I could see MySQL being much easier to work with. If I'm understanding you right, can I just drop the MySQL connector jar into my build path, and use normal SQL queries in my step definitions where needed? I guess I'm green, and naive, but I didn't think Cucumber and SQL would play nice together. If so, that would be awesome!

That code does look cumbersome. One approach would be to have two arrays. One would contain the two "in" values and the other would contain the 20 "ex" values. Then you could use two for loops to create the field names with the right index and build the list that way.



That is a great idea. I feel like I was close to thinking of that, but I can't take the credit Quick question though, if I were to try and create a hypothetical framework for web app testing, I would have to know the html source for each element for each site tested ahead of time right? Because not every site will have id's or name's that are identical? Is there a way to make a "universal" method to do things like that? If not, meh whatever, but now I'm curious.

You picked the best of breed tools.

I see two other things to remark on in your code:
1) The FirefoxDriver is a lot slower than the HtmlUnitDriver in Selenium. If you need to test in a real browser, you have to live with it. But if you are just testing functionality and a "simulated" browser does the job, it is worth considering.
2) In Java, we general throw Exception and not Throwable. The later includes system errors like running out of memory that automatically get thrown.
2) I see in a number of places that you catch an exception and print a stack trace. When this happens, you should fail the test and not proceed silently. You could add a fail statement. But it would be better to remove the try/catch block entirely and let JUnit deal with the error. Conveniently the default behavior is to fail the test and give you a stack trace!



1) Yea I prefer Chrome for normal browser business, but for the sake of this project Firefox was just slightly easier to work with. I will definitely look into HtmlUnitDriver though, that sounds like it could be super beneficial.
2) I do realize that Exception would have been better (isn't best practice to use the most specific expected exception first, then work your way down to throwable or exception?). The only reason I kept the step definition class' method declarations like that was because Cucumber populates them automatically for you when you run the Feature file with no methods in the step definition file, and it was quick and easy to use.
2)So if I'm understanding you correctly (again, I'm a newbie to all of this), just having the JUnit jar files added to the project will do that for me? That's great! I guess I added the try/catch blocks around each step definition after the fact because I thought it was good unit testing practice (I could very well be using that term incorrectly), but either way that is good to know

Thanks again for the response, and good information
9 years ago
So I used JUnit, Selenium, and Cucumber to make a basic web app test and I had some questions about how I might be able to improve it. This is just a personal practice type thing. Here is what I have so far:

CucumberRunner class:



Feature File:



And my step definitions:



(If you try and run any of that, obviously you'd need the jars for cucumber, selenium, and junit, plus firefox installed)

1. When I am populating the fields, instead of hardcoding 1 value in each, I'd like to set it up to be data driven through excel or MySQL (what word would I use to describe that? would robust be accurate there? or maybe versatile).

2. Also when populating the fields, that code looks cumbersome, and I'm trying to figure out a way I could use a loop to populate for each field, and what type of loop it would be?

3. Being new to automation (QA Engineer Level I intern), and testing in general, is there another/better method or tool to use if I wanted to stick with Java for automation? My job had me using QTP and VB Script, which was really powerful, for a little while to kind of introduce this to me, but I'd rather stick with Java because Java is where I want to focus (and they're giving me the option, so it's not like I'm being insubordinate with them)

Thanks in advance!

EDIT:

If you do decide to try and run this, these are the jars in the build path:

cucumber-core-1.1.5.jar
cucumber-html-0.2.3.jar
cucumber-java-1.1.5.jar
cucumber-junit-1.1.5.jar
cucumber-jvm-dep-1.0.3.jar
gherkin-2.12.1.jar
hamcrest-all-1.3.jar
junit-4.11.jar
selenium-server-standalone-2.44.0.jar

As an aside everything currently works perfect, so just clarifying that I don't have errors or anything like that. More so just looking for tools, or practices that I may be missing or not aware of in general, that I could improve this with. And again, thanks in advance!
9 years ago

Bear Bibeault wrote:Yes. The container has a well-debugged and performant connection pooling mechanism. You should be using it.

Connection pooling is like security -- it's really hard to roll your own and get it right.

I'm not sure of the details for setting it up for Tomcat7 (my clients are still on 6), so poke around and you are sure to fund instructions.



Thanks for the heads up sir. My classmate handled mostly everything regarding the database, but I'll see what I can find with some google searches.
9 years ago

Bear Bibeault wrote:If you are not using container-managed connection pooling, you're doing it wrong.



Is this something that is handled by Tomcat7 per se? Thanks for the response.
9 years ago

Paul Ngom wrote:David,
Do you close your database connection after
usage or any other resource you had opened
in your servlets or classes?



J. Kevin Robbins wrote:Paul, Good point. I'll bet it's exhausting the connection pool. That would explain why existing users can't get logged in either.

David, make sure you have a "finally" block that is closing the connection and the statement.



Hey guys, sorry for the delay, I've been tied up with some things for the past week or so, but I'm going to start looking into this again! I'll let you know what I find.
9 years ago

J. Kevin Robbins wrote:You answered correct, those log files are linked to that instance of Tomcat only. You could access them through the Manager app or an app like LambdaProbe if you can get to that server, but it's probably not accessible over the internet if they have it running at home. At least I hope not. That's a security nightmare and probably in violation of their ISP agreement.



Also, when this does happen, I open putty which is connected to his server. When I register a new user, what I'm seeing in putty is that the user isn't even being added to the users table in our database. But also, even existing users that are already there in the table can't log in. So strange, but maybe these details will help
9 years ago
Okay so here's another question: if we have this deployed on someone else's server on their machine at their home, would I be able to go into MY local machine's Tomcat folder and see the same logs? Or would we have to get that person to go through their local machine's logs since it's his Tomcat we're deploying on?

Not sure if how I worded that made any sense. I can clarify if I just confused anyone...

EDIT: I think I just answered my own question. I went into the logs folder on my machine, and the most recent log is from about 2 weeks ago, so I'm assuming the person whose Tomcat we're deployed to will have to go through the logs right? Unless there's a way to access those logs strictly through his Tomcat manager page which I can obviously access...
9 years ago

Anuj Sharma R wrote:

Wow so late tonight, and still I get a response!


That is the beauty of being in different time zones - your night is our start of the day :-).

You can see a 'logs' folder typically under your Tomcat deployment folder. There should multiple log files in there. Check for log file with stderr in its name and see if you can find any error/exceptions in there. I don't think you have cleared your logs folder as you were not aware where it was in first place . But in case logs are too big, you should clear those, redeploy the application and then wait for it to happen to decipher the problem from the logs.



Thanks for the response! I'll have to look into that as soon as I have a free minute!

Ulf Dittmer wrote:Agree, start by checking out the log files.

UNTIL...I undeploy and redeploy from the Tomcat manager page


Do you really mean "undeploy"? Or just "Stop" and "Start" (which together is the same as "Reload")? It would be a very unusual problem that requires redeploying.



Yep. I definitely have to undeploy and then redeploy. But like I said, after that, everything is working just as it should be. I agree, really strange.

J. Kevin Robbins wrote:The log file may also be called "catalina.out". I'm not sure about version 7, I'm still running 6. The most recent entries will be at the bottom of the log.



Thanks! I'll definitely be looking for the log files as soon as possible! I'll report back on what I find, if anything. Thanks to all for the suggestions!
9 years ago

Anuj Sharma R wrote:Hi David,

Did you check your Tomcat logs?



Wow so late tonight, and still I get a response! Why I love this site I haven't checked the Tomcat logs because quite honestly A: I don't know how, and B: I wouldn't know what to look for. Also, now that I've undeployed and redployed, if I were to check these logs, since everything is working, would I even find a problem? Or would I need to wait until it stops working again? Thanks very much for the response!
9 years ago
I'm not sure if this is the right forum to be posting this in, but my group (6 students) has a full web app with servlets, jsps, classes, and databases (mySQL). Everything works great (thank god)! But there's a strange problem that occurs:

We have a login and register page for our web app for new and existing users, and after deploying (we're using Tomcat7) everything works great, we can register a new user, login, and use the whole thing. ...But, after an undetermined amount of time the register page won't register new users to the database, and the login page won't login existing users...UNTIL...I undeploy and redeploy from the Tomcat manager page. And then? Everything works great and as intended again.

Does anyone have any ideas what could be causing this? Why would the behavior change if nothing on the server has changed? And why would a fresh deploy immediately fix the problem? Really new to all this, and it's very strange to me so any and all responses are welcomed and appreciated! Thanks in advance!

EDIT: The site is live and here is the address if this will help:

http://23.253.240.14:8080/Search
9 years ago

Paul Clapham wrote:Here's my opinion: you've got a whole lot of code and it's all untested. And servlets are a really poor testing environment. So why don't you back up a bit -- write a command-line program which tests your database access, to get that working first. Then you can put the working code into the servlet.



awesome advice! and by no coincidence, that is exactly what i did last night before i checked out. The database was connecting everything was working. and like you suggest, i then added in my classmates code and boom the exact same nullpointer. i think really, i might need to wait til my buddy is recovered so we can go through his code together, because it's still somewhat foreign to me. but at least i know my test code connected to his database just fine :)

great minds think alike :D

Paul Clapham wrote:You don't need the Class.forName line if two conditions apply: (1) you're using Java 6, and (2) the driver is JDBC 4.0 compatible. You should certainly be using Java 6 by now, and the latest version of the driver should certainly support JDBC 4.0, but anyway you should really ensure that both of those conditions do apply.



hey thanks again for the reply. Yea I saw and read both of those things a bunch, but many people were saying even past Java 5 that even though it's legacy code, that it's still needed. me? I don't know what's right either way. now as for the driver being jdbc 4.0 compatible, I'm not sure of, but I would assume it is since it's the most recent connector .jar

either way, I did try adding that line in, and poof, I get no errors in eclipse when I click that search button in the browser, BUT, I just get a blank white page. it was very refreshing to see honestly, but now I have to figure out if that's good or bad progress because hitting the search button with all empty fields should act as a wildcard and show all items in the product table of the database. either way, I got really burned out yesterday, so I may wait a little bit before I try and hammer back at this again today

Paul Clapham wrote:Classpath? Yes... but you posted some code for a servlet, so am I right in assuming that you're running this in some servlet environment like Tomcat? If so then the driver jar should go in the web application's WEB-INF/lib folder.



You are correct sir. Unfortunately I already have the jar in the WEB-INF/lib folder as well :/ One thing I'm seeing while googling this is the registering of the driver using

I'm going to try putting that in the code, because it's the one thing I'm not seeing in my classmates PDB class

Paul Clapham wrote:The primary problem was that the driver didn't load. The secondary problem was that you had a NPE elsewhere. It wasn't obvious to you that the secondary problem was because the primary problem had been ignored.



Yea and it's been giving me hell, that driver. I believe I have it placed in the right places. I read somewhere that it also needs to be added to the CLASS_PATH is that right? Just to be sure can you tell me exactly where that .jar needs to be? I thought I had that issue fixed because I was originally getting an error specifically regarding that driver, but I wasn't seeing that the last couple times I've tried running... ugh...


EDIT: whoops just checked again, and of course, still getting that no suitable driver error.

Paul Clapham wrote:Really that catch-block in the PDB class should be throwing a RuntimeException after logging the SQLException; as it's written it basically ignores the SQLException and allows processing to go on until something else fails. You noticed already how hard it is to track down the reason for the secondary failure, right?



No, I don't think I have. After seeing your first response I've been doing some googling on what I can do to remedy the DriverManager issue :/