예제 #1
0
        public static void OpenTransferList(this IWebDriver driver, EaAccount eaAccount)
        {
            driver.GoToTransferMenu(eaAccount);
            var transferTargets = driver.FindElement(By.ClassName("ut-tile-transfer-list"), 3);

            transferTargets.Click();
        }
예제 #2
0
        public async Task <IActionResult> Add(EaAccount eaAccount)
        {
            LoginStatus loginStatus  = LoginStatus.Unknown;
            var         user         = HttpContext.Items["User"] as User;
            var         chromeDriver = ChromeInstances.Instance.Add(eaAccount.Username);

            try
            {
                loginStatus = new LoginService(chromeDriver).Start(new Models.DTOs.LoginDTO {
                    Username = eaAccount.Username, Password = eaAccount.Password
                });
            }
            catch (ElementClickInterceptedException)
            {
                loginStatus = LoginStatus.Logged;
            }

            if (!user.EaAccounts.Any(ea => ea.Username == eaAccount.Username))
            {
                user.EaAccounts.Add(eaAccount);
                await _dbService.UpdateEaAccounts(user);
            }

            return(Ok(loginStatus));
        }
예제 #3
0
        public void RelistAll(EaAccount eaAccount)
        {
            _chromeDriver.OpenTransferList(eaAccount);
            var relistBtn = _chromeDriver.FindElement(By.XPath("//*[contains(text(), 'Re-list All')]"), 5);

            relistBtn.Click();
            var msgBox = _chromeDriver.FindElement(By.ClassName("dialog-body"), 10);
            var yesBtn = msgBox.FindElements(By.ClassName("btn-text")).FirstOrDefault(e => e.Text.ToUpper() == "YES");

            yesBtn.Click();
        }
예제 #4
0
        public static void GoToTransferMenu(this IWebDriver driver, EaAccount eaAccount)
        {
            // driver.TryLogin(eaAccount);
            if (driver.Url != "https://www.ea.com/fifa/ultimate-team/web-app/")
            {
                driver.Navigate().GoToUrl("https://www.ea.com/fifa/ultimate-team/web-app/");
                Thread.Sleep(10000);
            }

            var transferMenu = driver.FindElement(By.ClassName("icon-transfer"), 10);

            transferMenu.Click();
            Thread.Sleep(1000);
        }
예제 #5
0
        public static void OpenSearchTransferMarket(this IWebDriver driver, EaAccount eaAccount)
        {
            driver.GoToTransferMenu(eaAccount);
            Thread.Sleep(3000);
            var searchTransfer = driver.FindElement(By.ClassName("ut-tile-transfer-market"), 4);

            searchTransfer.Click();
            Thread.Sleep(1000);
            var clearParents = driver.FindElements(By.ClassName("search-price-header"), 5);

            foreach (var clearParent in clearParents)
            {
                clearParent.FindElement(By.ClassName("flat")).Click();
            }
        }
예제 #6
0
        public void Sell(SellPlayerDTO sellPlayerDTO, EaAccount eaAccount)
        {
            _chromeDriver.OpenTransferTargets(eaAccount);

            var wonItemsGroup = _chromeDriver.FindElements(By.ClassName("sectioned-item-list"), 10).ToList()[2];
            var itemList      = wonItemsGroup.FindElement(By.ClassName("itemList"));
            var players       = itemList.FindElements(By.ClassName("listFUTItem"));

            try
            {
                foreach (var player in players)
                {
                    _playersHelper.SellPlayer(player, sellPlayerDTO);
                }
            }
            catch (Exception)
            {
                Sell(sellPlayerDTO, eaAccount);
            }
        }
예제 #7
0
        public static void TryLogin(this IWebDriver driver, EaAccount eaAccount)
        {
            driver.Navigate().GoToUrl(@"https://www.ea.com/fifa/ultimate-team/web-app/");

            try
            {
                var startButton = driver.FindElement(By.ClassName("btn-standard"), 13);
                Thread.Sleep(3000);
                if (startButton == null)
                {
                    return;
                }
                startButton.Click();

                // Entering credentials
                driver.FindElement(By.Id("email"), 10).SendKeys(eaAccount.Username);
                driver.FindElement(By.Id("password")).SendKeys(eaAccount.Password);
                driver.FindElement(By.Id("btnLogin")).Click();
            }
            catch
            {
                return;
            }
        }
예제 #8
0
        public void BidPlayer(BidPlayerDTO bidPlayerDTO, EaAccount eaAccount)
        {
            _chromeDriver.OpenSearchTransferMarket(eaAccount);

            var nameInput = _chromeDriver.FindElement(By.ClassName("ut-text-input-control"), 3);

            nameInput.SendKeys(bidPlayerDTO.Player.Name);
            Thread.Sleep(500);
            var searchedPlayers = _chromeDriver.FindElementByClassName("playerResultsList").FindElements(By.CssSelector("button"));
            var selectPlayer    = searchedPlayers.FirstOrDefault(p => p.FindElement(By.CssSelector(".btn-subtext")).Text == bidPlayerDTO.Player.Rating.ToString());

            selectPlayer.Click();
            Thread.Sleep(1000);
            var priceElements      = _chromeDriver.FindElementsByClassName("numericInput");
            var maxBidPriceElement = priceElements[1];

            maxBidPriceElement.Clear();
            maxBidPriceElement.SendKeys(bidPlayerDTO.MaxPrice.ToString());
            Thread.Sleep(1000);
            var searchButton = _chromeDriver.FindElementByClassName("call-to-action");

            searchButton.Click();
            Thread.Sleep(4000);

            List <IWebElement> players;

            do
            {
                players = _playersHelper.InitPlayers();
            }while (PlaceBid(players, bidPlayerDTO, eaAccount));

            do
            {
                players = _playersHelper.InitTargetListOutbidBidPlayers();
            }while (PlaceBidActivePlayers(players, bidPlayerDTO));
        }
예제 #9
0
        public void RelistPlayer(SellPlayerDTO sellPlayerDTO, EaAccount eaAccount)
        {
            _chromeDriver.OpenTransferList(eaAccount);

            ListPlayer(sellPlayerDTO);
        }
예제 #10
0
        private bool PlaceBid(List <IWebElement> players, BidPlayerDTO bidPlayerDTO, EaAccount eaAccount)
        {
            try
            {
                foreach (var player in players)
                {
                    var transferListFullElements = _chromeDriver.FindElementsByClassName("ui-dialog-type-alert");
                    if (transferListFullElements.Count > 0)
                    {
                        var transferListFullWindow = transferListFullElements.FirstOrDefault();
                        var okButton = transferListFullWindow.FindElement(By.ClassName("ut-button-group"));
                        Thread.Sleep(840);
                        okButton.Click();
                        Thread.Sleep(840);

                        if (_clearTargetList.TryClearTargetList(_chromeDriver, bidPlayerDTO, eaAccount))
                        {
                            BidPlayer(bidPlayerDTO, eaAccount);
                        }
                        return(false);
                    }

                    var classes = player.GetAttribute("class").Split(" ").ToList();
                    if (classes.Contains("highest-bid"))
                    {
                        _currentPlayersBidded++;
                        continue;
                    }

                    player.Click();
                    var period          = _chromeDriver.FindElementByClassName("subContent").Text;
                    var isPeriodTooLong = period.Contains("Hour") | period.Contains("Day");
                    if (isPeriodTooLong)
                    {
                        return(false);
                    }

                    int.TryParse(_chromeDriver.FindElementByClassName("auctionInfo").FindElement(By.ClassName("currency-coins")).Text, out int currentPrice);
                    if (currentPrice > bidPlayerDTO.MaxPrice)
                    {
                        continue;
                    }

                    // var inputPrice = _chromeDriver.FindElementByClassName("numericInput");
                    // inputPrice.Clear();
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(Keys.Backspace);
                    // inputPrice.SendKeys(bidPlayerDTO.MaxPrice.ToString());
                    var bidButton = _chromeDriver.FindElementByClassName("bidButton");
                    if (_currentPlayersBidded >= bidPlayerDTO.MaxActiveBids)
                    {
                        return(false);
                    }

                    _currentPlayersBidded++;
                    bidButton.Click();
                    Thread.Sleep(2000);
                }

                try
                {
                    var nextPage = _chromeDriver.FindElement(By.ClassName("next"));
                    nextPage.Click();
                    Thread.Sleep(3000);
                }
                catch
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                players = _playersHelper.InitPlayers();
                PlaceBid(players, bidPlayerDTO, eaAccount);
                return(true);
            }
        }
예제 #11
0
        public bool TryClearTargetList(ChromeDriver driver, BidPlayerDTO bidPlayerDTO, EaAccount eaAccount)
        {
            _playersHelper = new PlayersHelper(driver);

            try
            {
                driver.OpenTransferTargets(eaAccount);
                var clearExpired = driver.FindElement(By.XPath("//*[contains(text(), 'Clear Expired')]"), 5);
                clearExpired.Click();
                UnwatchOverpricedPlayers(bidPlayerDTO);
            }
            catch
            {
                return(false);
            }

            return(true);
        }