Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
update logging in trait to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
johnduffell committed Jul 22, 2014
1 parent 1bcde38 commit 37b3000
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/main/scala/com/gu/automation/signin/LogIn.scala
Expand Up @@ -26,7 +26,13 @@ object LogIn {
def getCookieDomain(url: String) =
"""http(s?)://([^.]*(\.))?([^/]+).*$""".r.replaceAllIn(url, "$3$4")

def apply(user: Option[String])(implicit driver: WebDriver) = {
def apply()(implicit driver: WebDriver) = {
apply(None, driver)
}
def apply(user: String)(implicit driver: WebDriver) = {
apply(Some(user), driver)
}
private def apply(user: Option[String], driver: WebDriver) = {
val idApiRoot = Config().getIdApiRoot()
val loginEmail = Config().getLoginEmail(user)
val loginPassword = Config().getLoginPassword(user)
Expand All @@ -37,8 +43,11 @@ object LogIn {

val future = AuthApi(idApiRoot).authenticate(loginEmail, loginPassword)

val accessToken = Await.result(future, 30.seconds)
val cookies = accessToken match { case Right(cookies) => cookies }
val accessToken = Await.result(future, 10.seconds)
val cookies = accessToken match {
case Right(cookies) => cookies
case Left(error) => throw new RuntimeException(s"authenticate $loginEmail failed: $error")
}
cookies.foreach {
case (key, value) =>
val isSecure = key.startsWith("SC_")
Expand Down
2 changes: 0 additions & 2 deletions src/test/resources/project.conf

This file was deleted.

20 changes: 16 additions & 4 deletions src/test/scala/com/gu/automation/signin/LoggingInTest.scala
Expand Up @@ -14,20 +14,32 @@ class LoggingInTest extends WebDriverFeatureSpec with Matchers {
scenario("check we can get the right cookie domains") { _ =>

LogIn.getCookieDomain("http://www.theguardian.com/uk") should be (".theguardian.com")
LogIn.getCookieDomain("http://localhost:9000/") should be ("localhost:9000")
LogIn.getCookieDomain("https://www.theguardian.com/uk") should be (".theguardian.com")
LogIn.getCookieDomain("https://m.code.dev-theguardian.com/") should be (".code.dev-theguardian.com")

}

// could add another test with a fake AuthApi checking the cookies really are set

/**
* scenarioWeb handles starting and stopping the browser, you will have to declare an implicit driver as shown
* This is an end to end test that we really end up logged in.
*
* To pass it needs a local.conf containing something like
*
* "idApiRoot" : "https://idapi.code.dev-theguardian.com"
* testBaseUrl: "http://m.code.dev-theguardian.com"
* memberLogin: {
* "loginEmail" : "regidqa@gmail.com"
* "loginPassword" : "ask_gwyn!"
* }
* browser: chrome
*/
scenarioWeb("check we are logged in when we have added the cookies") { implicit driver: WebDriver =>

LogIn(Some("memberLogin"))
// ExamplePage.goto()
LogIn("memberLogin")

// now go to a URL where we are probably logged in
driver.get(Config().getTestBaseUrl())
val userSpan = driver.findElement(By.xpath("//div[@data-component='identity-profile']")).findElement(By.className("js-profile-info"))
userSpan.getText should be ("Reg Idtester")
Expand Down

0 comments on commit 37b3000

Please sign in to comment.