Any tips for getting a PhD position?
While answer to your question needs more detail, but in general the answer looks like this:

Starting PhD in different universities is different. In many universities , faculty member receive application from the PhD applicant and evaluate individually. However, in other universities mostly in US, the application is evaluated by the committee. 

In the first case, certainly, the best way to start is to initiate a communication with potential PhD supervisors by sending an Email -as you said- along with your CV, academic history, SoP, and research proposal (proposal is not needed in US, but should not be a problem if you send). However, I think it may not really work if you ask them for assignment (maybe it works in some universities that I don't know).

One thing I noticed when I was searching for my PhD is that many supervisor write some notes on their pages and provide some instruction for potential students to follow. If you don't simply follow them you won't be able to get position from them. Try to read their pages as carefully as you can.

I admit that there are tension in getting PhD position. But it is all right and should be okay. Some guidelines may help you figure it our.

In general, to successfully secure a PhD position, you need certain qualifications and certificates listed as following:


Bachelor degree in relevant course with high GPA/CGPA (this is must)
Master degree in relevant course with high GPA/CPGA (This is not really a MUST-have requirement, since many universities offer PhD without having Master).
English Proficiency certificate (for English speaking countries) if you English is not your native language.
2/3 reference letters in your favor (no wonder).
GRE for US-based universities.
Money to pay tuition fee (supervisors consider this as well. If you need financial assistance you should be really good compare to others).


Thats all REQUIREMENTS. But, they are not sufficient to convince a potential academician to offer you position, especially paid positions which are very competitive. If you want to enhance your chance, I think in CS you need the following qualifications:


Good quality publication(s) in good publishing venues (top ranked conference and journals)
Research experience (It may be true that Master by research graduates have better chance here).
Working experience in relevant areas
Teaching experience 
Professional certificates from well-known organizations like Microsoft, and Oracle.
Volunteer jobs in the society (I heard a lot about it)
Academic or professional Awards like best student, best thesis, and best paper award. 
GRE and SAT certificates 
Intellectual properties (patents)


But, I think the most important thing is the first impression that you make using your first Email, CV, SoP, statement of research and so on. If they look professional and neat, it attracts potential supervisor's attention and will evaluate your application optimistically.

Don't give up. You have to find the RIGHT supervisor, in the RIGHT university, at the RIGHT time, using the RIGHT channel. Keep trying and you will succeed.