From 37b3000840eb4d9c8b952dd3f2cb91f15680104d Mon Sep 17 00:00:00 2001 From: John Duffell Date: Tue, 22 Jul 2014 11:04:57 +0100 Subject: [PATCH] update logging in trait to upload --- .../com/gu/automation/signin/LogIn.scala | 15 +++++++++++--- src/test/resources/project.conf | 2 -- .../gu/automation/signin/LoggingInTest.scala | 20 +++++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) delete mode 100644 src/test/resources/project.conf diff --git a/src/main/scala/com/gu/automation/signin/LogIn.scala b/src/main/scala/com/gu/automation/signin/LogIn.scala index 991ba7a..e3f5c19 100644 --- a/src/main/scala/com/gu/automation/signin/LogIn.scala +++ b/src/main/scala/com/gu/automation/signin/LogIn.scala @@ -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) @@ -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_") diff --git a/src/test/resources/project.conf b/src/test/resources/project.conf deleted file mode 100644 index 865414f..0000000 --- a/src/test/resources/project.conf +++ /dev/null @@ -1,2 +0,0 @@ -"idApiRoot" : "https://idapi.code.dev-theguardian.com" -testBaseUrl: "http://m.code.dev-theguardian.com" diff --git a/src/test/scala/com/gu/automation/signin/LoggingInTest.scala b/src/test/scala/com/gu/automation/signin/LoggingInTest.scala index b40e885..d08fdb0 100644 --- a/src/test/scala/com/gu/automation/signin/LoggingInTest.scala +++ b/src/test/scala/com/gu/automation/signin/LoggingInTest.scala @@ -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")