@Test @UseUnstablePageLoadStrategy public void signUpWithFacebook() { new RemoveFacebookPageObject(driver) .removeWikiaApps(user.getEmail(), user.getPassword()) .logOutFB(); WikiBasePageObject base = new WikiBasePageObject(driver); base.openWikiPage(wikiURL); FacebookMainPageObject fbLogin = base.openFacebookMainPage(); FacebookUserPageObject userFB; userFB = fbLogin.login(user.getEmail(), user.getPassword()); userFB.verifyPageLogo(); SignUpPageObject signUp = userFB.navigateToSpecialSignUpPage(wikiURL); FacebookSignupModalComponentObject fbModal = signUp.clickFacebookSignUp(); fbModal.acceptWikiaAppPolicy(); String userName = "******" + DateTime.now().getMillis(); String password = "******" + DateTime.now().getMillis(); fbModal.typeUserName(userName); fbModal.typePassword(password); fbModal.createAccount(); base.openWikiPage(wikiURL); base.appendToUrl("noads=1"); base.verifyUserLoggedIn(userName); base.logOut(wikiURL); }
public String logInCookie(String userName, String password, String wikiURL) { String client_id = HeliosConfig.getClientId(); String client_secret = HeliosConfig.getClientSecret(); String heliosBaseUrl = HeliosConfig.getUrl(HeliosConfig.HeliosController.TOKEN); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(heliosBaseUrl); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("grant_type", HeliosConfig.GrantType.PASSWORD.getGrantType())); nvps.add(new BasicNameValuePair("client_id", client_id)); nvps.add(new BasicNameValuePair("client_secret", client_secret)); nvps.add(new BasicNameValuePair("username", userName)); nvps.add(new BasicNameValuePair("password", password)); CloseableHttpResponse response = null; httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); try { response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); JSONObject responseValue = new JSONObject(EntityUtils.toString(entity)); EntityUtils.consume(entity); PageObjectLogging.log("LOGIN HEADERS: ", response.toString(), true); PageObjectLogging.log("LOGIN RESPONSE: ", responseValue.toString(), true); String token = responseValue.getString("access_token"); String domian = Configuration.getEnvType().equals("dev") ? ".wikia-dev.com" : ".wikia.com"; driver.manage().addCookie(new Cookie("access_token", token, domian, null, null)); if (driver.getCurrentUrl().contains("Logout")) { driver.get(wikiURL); } else { driver.navigate().refresh(); } verifyUserLoggedIn(userName); PageObjectLogging.log( "loginCookie", "user was logged in by by helios using acces token: " + token, true); return token; } catch (TimeoutException e) { PageObjectLogging.log("loginCookie", "page timeout after login by cookie", false); } catch (UnsupportedEncodingException | ClientProtocolException e) { PageObjectLogging.log("logInCookie", "UnsupportedEncodingException", false); throw new WebDriverException(); } catch (JSONException e) { PageObjectLogging.log("logInCookie", "Problem with parsing JSON response", false); throw new WebDriverException(); } catch (IOException e) { PageObjectLogging.log("logInCookie", "IO Exception", false); } finally { try { response.close(); } catch (IOException | NullPointerException e) { PageObjectLogging.log("logInCookie", "IO Exception", false); } } return ""; }