What happens to the electric field at the boundary of a dielectric? The question in the title is a broader one, but for now, I want to confine myself to the following problem.

I have the task to find the potential difference between points A and B shown in the diagram.

The point B is vertically below A. $k_1$, $k_2$ and $k_3$ refer to the dielectric constants of the slabs. The thickness of the slab of dielectric constant $k_1$ is $x$, and correspondingly for $k_2$ is $y$.

Now, using formulae for parallely connected capacitors, we find the potentials of points A and B to be equal to:
$$V_A = \dfrac{V}{1+\frac{k_2}{k_1}\frac xy}$$
$$V_B = \dfrac{V}{1+\frac xy}$$
But, if we calculate the integral $\displaystyle V_{AB}=-\int_B^A\vec{E\,}\cdot\mathrm d\vec{r\,}$, then we get potential difference to be zero! Why does this integral not give the actual potential difference between the two points? I suspect this is due to something wierd happening to the field at the boundary of $k_3$ slab and the $k_1$ and $k_2$ slabs.
Thank you.
 A: I think the answer is clearer if you consider the equipotential as shown in the diagram below.  Forgive their straight line nature as they were easier to draw that way.

Given that $\vec E$ must be perpendicular to an equipotential surface then in your computation of potential difference $\displaystyle V_{AB}=-\int_B^A\vec{E\,}\cdot\mathrm d\vec{r\,}$ the value of $\vec E \cdot d\vec r$ is not zero along the whole path.

Later:
I am sure that the potential and hence the electric field pattern can be computed numerically but as I do not have the facility to do that consideration of a simpler arrangement which might help understand what is going on.  
Consider a pair of parallel plates area $2A$, separation $d$ with a potential difference of $V$ between them.  Between the plates there is air (relative permittivity $\epsilon_r = 1$) and a dielectric  ($\epsilon_r = 2$) of thickness $\frac d 2$ and area $A$ as shown in the diagram left-hand below in which the induced charges on the dielectric are not shown.

The various values shown in the diagram can be obtained by considering the setup as a stand alone capacitor of area $A$, separation $d$ with air between the plates ($Y$ and $Z$) and another stand alone capacitor of area $A$ with a mixed dielectric between the plates ($W$ and $X$).  
With the potential difference across the two capacitors $V$ the same then if the charge on the air only capacitor is $3q$ then the charge of the mixed dielectric capacitor is $4q$.
This results in different net electric field $E_n$ within the capacitors.
Now consider what will happen when these two capacitors are combined.
The electric field in region $W$ is less than that in region $Y$ and the electric field in region $X$ is greater than that in region $Z$.
Since in practice there cannot be a discontinuity of the electric field in the air some negative charge $-4q$ must move down the right-hand conducting plate ($0$) with the consequence that the electric field only be perpendicular to the right hand conducting plate at its surface and not inside the body of air.
The induced charges on the dielectric will also move with some of them residing on the bottom horizontal part of the dielectric.
I then thought of another “simple” arrangement where the dielectric in the left-hand diagram is replaced by a conductor to give the situation shown in the right-hand diagram.
Again two capacitors charged so that the potential difference across the plates is $V$ and then joined together.
Again some of the negative charge $-2q$ will move down the right-hand plate and also there will probably a concentration of charge near the corner $Z$ and a deficit of charges around corner $Y$?  
So again there will be a distortion of the electric field and the electric field lines would not be perpendicular to the conductors except close to the conductors.
Without a numerical computation other than guessing where the equipotential lines are and drawing the electric field lines at right angles to them that is as far as hand waving goes? 
A: Boundary conditions of electromagnetic waves are well looked into because of the nature between polarization and reflection. However in this particular case it is rather simple, it is the evaluation of a contour integral over the boundary. This is done by summing the length elements of the pill-box shape that is typically used in this analysis in the correct +/- convention.

