The normal procedure is to require the foreigner to apply for the work permit and resident visa before entering the country, although some countries do allow you to apply after being in country and securing an employment contract. In other words, in most instances, you cannot just arrive in country, look for employment, and then apply for a resident visa. Instead, you must have an employment contract in hand before arriving in country. The easiest way to get a work permit is to have an employment contract with a company that routinely takes care of work permit requirements. They, rather than you, must deal with the complexities of the government bureaucracy.
Most countries follow a similar pattern in regards to work permits and resident visas.
When applying for a work permit and resident visa, employers must provide evidence that the job in question cannot be filled by a local worker with similar skills. The bureaucracy takes its time in processing such applications. You will witness a great deal of bureaucratic inertia in the process of acting on your application. Foreigners must pay local taxes and special resident visa fees. Furthermore, foreigners may be restricted on how much local currency they can take out of the country.