generics - How can I use Scala's Manifest class to instantiate the erased class at runtime? -
i'm doing webdriver+pageobject stuff.
(if not familiar pageobjects, pattern have class representing each page on site exposes functions of page using domain language, hiding html stuff test.)
i want lazy , have 1 'submit' method in abstract page class other pages extend from. want method new next page subclass , return it.
here have in page class:
def submitexpecting[p <: page[p]](implicit m: manifest[_]): p = { driver.findelement(by.xpath("//input[@type='submit']")).click m.erasure.getconstructor(classof[webdriver]).newinstance(driver).asinstanceof[p] }
and here's how i'm calling it:
val userhomepage = usersignuppage .login("graham") .accepttermsandconditions .submitexpecting[userhomepage]
compiling this, get:
error: not find implicit value parameter m: manifest[_] .submitexpecting[userhomepage]
i thought being smart, i'm not. ;) doing wrong?
you need make manifest
related type parameter, i.e.
def submitexpecting[p <: page[p]](implicit m: manifest[p]): p
Comments
Post a Comment