GEB TEST WITH SELECT2 JQUERY PLUGIN

  1. Problem

When using Select2 Jquery plugin in my project, there is a problem in writing Geb functional tests because Geb does not understand Select2 via its default select mechanism.

Fortunately, Geb provides the mechanism to extend the default navigators to write our own method in a need of using third party library. Here is the solution.

2. Solution

2.1 Extend navigator classes NonEmptyNavigator and EmptyNavigator

Geb provides two navigators classes NonEmptyNavigator and EmptyNavigator. If the selector $(‘#fieldId’) returns an element, it will be bound to a NonEmptyNavigator, else it will use EmptyNavigator.

Thus, first of all, create two subclasses which extend from NonEmptyNavigator and EmptyNavigator as below:

import geb.Browser
import org.openqa.selenium.WebElement

class NonEmptyNavigator extends geb.navigator.NonEmptyNavigator {

    NonEmptyNavigator(Browser browser, Collection<? extends WebElement> contextElements) {
        super(browser, contextElements)
    }
}
import geb.Browser

class EmptyNavigator extends geb.navigator.EmptyNavigator {
    EmptyNavigator(Browser browser) {
        super(browser)
    }
}

2.2. In GebConfig.groovy, add the below code to use custom navigator

innerNavigatorFactory = { Browser browser, List<WebElement> elements ->
    elements ? new NonEmptyNavigator(browser, elements) : new EmptyNavigator(browser)
}

2.3 Convert the select2 Jquery script to Geb friendly expression by using the built-in javascript executor. 

To do this, add the corresponding method into NonEmptyNavigagor class above

  • Method to set value Select2
void select(String value){ 
     browser.js.exec(firstElement(), value, 'jQuery(arguments[0]).select2("val", arguments[1]);')
  }
  • Method to get the selected value of Select2
String getSelectedValue() {
browser.js.exec(firstElement(), ‘return jQuery(arguments[0]).select2(“val”);’)
}

2.4 Now in your Geb Test, you can call the new methods which have been added to choose the values and get the selected values from Select2

$(‘#fieldId’).select(‘California’)
$(‘#fieldId’).getSelectedValue()

3. References

https://fbflex.wordpress.com/2013/11/25/extending-geb-element/

Tips for getting interview

Searching for the job over the last few weeks helps me to understand more the full hiring cycle in the US. As the time goes by, things may be easily forgotten. Therefore, I would like to write these wonderful hiring processes that I had great opportunity to experience down and share here.

Interview process

There are two cases: direct hire and indirect hire. In the direct hire, candidate applies for the job directly to the company and the hiring is processed by internal recruiter. In indirect hire, candidate will work mostly with external recruiter instead of the company.

1. Screening interview: involve coding & algorithm questions. This is as high as in-person interview. Coding will be conducted via many online synchronized document editors. Alternatively, interviewer may ask candidates to complete coding at home and send them the code when done. Screening interview can be conducted 2-3 times before onsite interview

2. Onsite interview: There are usually 4-6 in-person interview. Most of them are technical interviews about coding & algorithm. There are also questions about candidate’s resume. In addition, there is also one interview over the lunch which is not technical. This is a good chance to discuss candidate’s interest and ask about company cultures.

The internal/external recruiter will respond to the candidate within a week.

How to prepare for the interview

1. Large company: if you want to work for big company like Google, Facebook, Amazon, Microsoft, prepare algorithm and data structures. Big company concerns processing big data, scalability…so these are also the areas to be looked into.

2. Small & Mid-size company: Focus mostly technology and your experience. They will ask how you are good at java skills, spring/hibernate, HTML, CSS,….for example.

Steps

1. Prepare your profile, resume and profolio

2. Make a list of preferred company

3. Practice algorithm and data structures. Here are the good sites to practice 

  1. leetcode.com
  2. hackerrank.com

4. Practice interview questions at http://www.careercup.com. This is a delicate site to help candidate prepare for technical interview questions.

5. Do several mock interviews and then repeat step 3-4.

Hope these sharing are useful and I appreciate comments if I miss anything!

How to land job offer in 3-4 weeks


In this article, I would like to share the tips how to land the job offer in 3-4 weeks.

In order to land the job offer in the short period of time, it’s important that you practice algorithm and data structures problem frequently (either in your spare time or after work). The more you practice algorithms and data structures, the more chances you have to be offered the job.

  1. Practice the algorithm and data structures

There are many sites to practice algorithms and data structures such as hackerank, careercup, topcoder…In my experience, these two are efficient.

1.1 Buy a book “Cracking the code interview” and revise your knowledge on the data structure

1.2 Practice the problems on leetcode.com website

  • If you come from another country other than US, there is always a gap of interview process in US and in your country. For example, in my country the interview is completely different from here. Thus, if you are new, practice first with the easy problem. The most important thing is that “try to resolve the problem by yourself, don’t look at the solution at first”. This will help you to build your brain to resolve another problem or more complicate problem.
  • Target to resolve about 200 problems: each day you practice 5-10 problems, then you will be ready for job interview for software engineer position in 40 days or 20 days.
  • There is also another good website is http://www.geeksforgeeks.org/. This site provides the solution/approach to resolve the problem first before jumping to the code. Thus it’s very useful.
  • When you have already resolve the problem, don’t move on to the next. Think if you can optimize it. For example:
  • Check if you can reduce the complexity
  • Check if you can reduce the space
  • Check if you can reduce the number line of codes

1.3 Practice system design: a good website is interviewbit

2. Market yourself

Make sure you write a very good and attractive resume. Your linkedin profile should cover your strength, experience, skills necessary for the job. In addition, it’s very important that you have your own project or websites which will attract more employers.

3. Prepare banking of questions

Per your experience and skills, prepare the list of possible questions and answers for each technology track. This is extremely useful when you have to interview with many companies. Going over the your note before each interview keep you always ready for every questions about your skills and experience.

4. Apply for the desired positions

If you come from another country, it’s a bit difficult to know a good website to apply for the job. Per my experience, these are very good websites

  • Via referral: if you have your friend work at your desired company, ask them for referral. The process will be very fast to get an interview
  • hired.com : this is very good website. The company will find us for the job, instead of our applying for the positions at the company. Therefore, the hiring process is very fast.
  • stackoverflow: list all the companies’ job description and their visa sponsoring
  • Linkedin, Indeed: make sure you choose the filter to apply for the job. Per my experience, I always choose filter for 1 day with the newest job
  • Company website: this process of applying takes a lot of time because you have to fill a lot of information in the form.

5. Tips for interview

  • Before each interview, make sure you study the company products and websites. Then add the question and answer into your note about “Why are you interested in the position at company x?” These are often asked by HR recruiter at the very first stage of the interview process
  • Get yourself familiar with online coding tool such as coderpad.io or codility so that you will not be surprised on the phone screen or coding challenge
  • During your interview with company X, make sure to have a separate note for that company. As you will interview with many companies, these notes keep you not get lost the information when you get into the deeper stages of the interview (which can take 3-4 weeks)
  • There are also some companies providing you take home project (some are very easy, some are very challenging): make sure to write a clean code
  • Onsite interview: often takes very long, about 4-6 hours. Thus, make sure you have big breakfast before interview (otherwise you will get tired or hungry in the middle of the interview)
  • Big companies: Expedia, Amazon…they test you very challenging problems. The good thing is these companies provide you a very good learning exercise. Every time I interview with them, I learn something. Very interesting problem and they help candidate the best solutions.
  • Middle size/small companies: Average problems. The interviewer rarely provide you the best solutions so almost no learning exercises.

6. Technology trend

At this time, for java track, the market requires developer skills in Spring Boot, microservices, python, Amazon Web services, React Js, Angular…so make sure to equip yourself with these technologies to get as many interviews as possible.

7. Organize your interview process

Normally the process to have job with direct hire takes about 3-4 weeks or more (up to 8 weeks). So if you are targeting direct hire or big companies, a good strategy is the best.

  • Try to interview with small companies or average companies first to gain interview experience. These interview will help you learn how to answer and learn from failure. 
  • Try to push your desired company in the middle/end (as the interview may be very difficult) and you have no time to fail for your desired company.
  • If your current skills/experience can’t match with big company like Amazon, Expedia or Google…try to interview with them first. They often provide you very good learning exercise in the interview so it’s very good for your next interview after that even though you fail.

These are tips that I can think of write now. Will write more when having time.

Any comments, welcome!