@@ -99,7 +99,7 @@ public async Task AuthenticateWithPinCodeAsync()
99
99
return ;
100
100
101
101
// act
102
- var authenticationClient = new TwitterClient ( EndToEndTestConfig . TweetinviApi . Credentials ) ;
102
+ var authenticationClient = new TwitterClient ( EndToEndTestConfig . TweetinviTest . Credentials ) ;
103
103
var authenticationRequest = await authenticationClient . Auth . RequestAuthenticationUrlAsync ( ) ;
104
104
var authUrl = authenticationRequest . AuthorizationURL ;
105
105
@@ -191,7 +191,7 @@ private async Task<TwitterClient> GetAuthenticatedTwitterClientViaRedirectAsync(
191
191
{
192
192
var expectAuthRequestTask = AExtensions . HttpRequest ( new AssertHttpRequestConfig ( _logger . WriteLine ) )
193
193
. OnPort ( 8042 )
194
- . WithATimeoutOf ( TimeSpan . FromSeconds ( 30 ) )
194
+ . WithATimeoutOf ( TimeSpan . FromSeconds ( 40 ) )
195
195
. Matching ( request => { return request . Url . AbsoluteUri . Contains ( authRequest . AuthorizationKey ) ; } )
196
196
. MustHaveHappenedAsync ( ) ;
197
197
@@ -265,20 +265,31 @@ private void AuthenticateOnTwitterWebsite(string authUrl, RemoteWebDriver webDri
265
265
266
266
Task . Delay ( 2000 ) . Wait ( ) ;
267
267
268
- var emailTextFields = webDriver . FindElementsByClassName ( "js-username-field" ) ;
269
- // var emailTextFields = webDriver.FindElements(By.Name("session[username_or_email]"));
268
+ // var emailTextFields = webDriver.FindElementsByClassName("js-username-field");
269
+
270
+ var emailTextFields = webDriver . FindElements ( By . Name ( "session[username_or_email]" ) ) ;
270
271
var isTwitterPromptingForSecondAuthentication = emailTextFields . Count == 1 ;
271
272
273
+ // NOTE : If this appears to redirect to twitter.com instead of the redirect page
274
+ // It means that Twitter detected strange action. Need to authenticate and share access code
275
+
272
276
if ( isTwitterPromptingForSecondAuthentication )
273
277
{
274
- var secondPasswordTextField = webDriver . FindElementByClassName ( "js-password-field" ) ;
275
- // var secondPasswordTextField = webDriver.FindElement(By.Name("session[password]"));
278
+ // var secondPasswordTextField = webDriver.FindElementByClassName("js-password-field");
279
+ var secondPasswordTextField = webDriver . FindElement ( By . Name ( "session[password]" ) ) ;
276
280
emailTextFields [ 0 ] . SendKeys ( Environment . GetEnvironmentVariable ( "TWEETINVI_EMAIL" ) ) ;
277
281
secondPasswordTextField . SendKeys ( Environment . GetEnvironmentVariable ( "TWEETINVI_PASS" ) ) ;
278
282
secondPasswordTextField . Submit ( ) ;
279
283
new WebDriverWait ( webDriver , TimeSpan . FromSeconds ( 10 ) ) . Until ( d => ( ( IJavaScriptExecutor ) d ) . ExecuteScript ( "return document.readyState" ) . Equals ( "complete" ) ) ;
280
284
}
281
285
286
+ var currentUrl = webDriver . Url ;
287
+ if ( currentUrl . Contains ( "twitter" ) )
288
+ {
289
+ webDriver . Url = authUrl ;
290
+ new WebDriverWait ( webDriver , TimeSpan . FromSeconds ( 10 ) ) . Until ( d => ( ( IJavaScriptExecutor ) d ) . ExecuteScript ( "return document.readyState" ) . Equals ( "complete" ) ) ;
291
+ }
292
+
282
293
_logger . WriteLine ( $ "{ DateTime . Now . ToLongTimeString ( ) } - authentication completed") ;
283
294
}
284
295
0 commit comments