Google Play排行榜随机工作

时间:2016-06-30 20:04:29

标签: android google-play-services google-play-games leaderboard

我在我的libgdx应用中添加了10个Google Play排行榜。现在我想从每个排行榜获得玩家的排名。我用这个函数:

namespace CodedUITestProject1
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class CodedUITest1
    {
        public CodedUITest1()
        {
        }

        [TestMethod]
        public void CodedUITestMethod1()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            this.UIMap.RecordedMethod1();
        }

        #region Additional test attributes

        // You can use the following additional attributes as you write your tests:

        ////Use TestInitialize to run code before running each test 
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //}

        ////Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //}

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        private TestContext testContextInstance;

        public UIMap UIMap
        {
            get
            {
                if ((this.map == null))
                {
                    this.map = new UIMap();
                }

                return this.map;
            }
        }

        private UIMap map;
    }
}

namespace CodedUITestProject1
{
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text.RegularExpressions;
    using System.Windows.Input;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
    using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
    using MouseButtons = System.Windows.Forms.MouseButtons;


    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public partial class UIMap
    {

        /// <summary>
        /// RecordedMethod1
        /// </summary>
        public void RecordedMethod1()
        {
            #region Variable Declarations
            WinClient uIStartClient = this.UIItemWindow.UIStartClient;
            WinControl uILogoImage = this.UIStartmenuWindow.UICalculatorListItem.UILogoImage;
            WinButton uIItem5Button = this.UICalculatorWindow.UIItemWindow.UIItem5Button;
            WinButton uIMultiplyButton = this.UICalculatorWindow.UIItemWindow1.UIMultiplyButton;
            WinButton uIItem6Button = this.UICalculatorWindow.UIItemWindow2.UIItem6Button;
            WinButton uIEqualsButton = this.UICalculatorWindow.UIItemWindow3.UIEqualsButton;
            #endregion

            // Click 'Start' client
            Mouse.Click(uIStartClient, new Point(7, 1572));

            // Click 'Logo' image
            Mouse.Click(uILogoImage, new Point(30, 12));

            // Click '5' button
            Mouse.Click(uIItem5Button, new Point(13, 12));

            // Click 'Multiply' button
            Mouse.Click(uIMultiplyButton, new Point(21, 12));

            // Click '6' button
            Mouse.Click(uIItem6Button, new Point(16, 15));

            // Click 'Equals' button
            Mouse.Click(uIEqualsButton, new Point(19, 26));
        }

        #region Properties
        public UIItemWindow UIItemWindow
        {
            get
            {
                if ((this.mUIItemWindow == null))
                {
                    this.mUIItemWindow = new UIItemWindow();
                }
                return this.mUIItemWindow;
            }
        }

        public UIStartmenuWindow UIStartmenuWindow
        {
            get
            {
                if ((this.mUIStartmenuWindow == null))
                {
                    this.mUIStartmenuWindow = new UIStartmenuWindow();
                }
                return this.mUIStartmenuWindow;
            }
        }

        public UICalculatorWindow UICalculatorWindow
        {
            get
            {
                if ((this.mUICalculatorWindow == null))
                {
                    this.mUICalculatorWindow = new UICalculatorWindow();
                }
                return this.mUICalculatorWindow;
            }
        }
        #endregion

        #region Fields
        private UIItemWindow mUIItemWindow;

        private UIStartmenuWindow mUIStartmenuWindow;

        private UICalculatorWindow mUICalculatorWindow;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIItemWindow : WinWindow
    {

        public UIItemWindow()
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.AccessibleName] = "Desktop";
            this.SearchProperties[WinWindow.PropertyNames.ClassName] = "#32769";
            #endregion
        }

        #region Properties
        public WinClient UIStartClient
        {
            get
            {
                if ((this.mUIStartClient == null))
                {
                    this.mUIStartClient = new WinClient(this);
                    #region Search Criteria
                    this.mUIStartClient.SearchProperties[WinControl.PropertyNames.Name] = "Start";
                    this.mUIStartClient.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
                    this.mUIStartClient.SearchConfigurations.Remove(SearchConfiguration.VisibleOnly);
                    #endregion
                }
                return this.mUIStartClient;
            }
        }
        #endregion

        #region Fields
        private WinClient mUIStartClient;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIStartmenuWindow : WinWindow
    {

        public UIStartmenuWindow()
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.Name] = "Start menu";
            this.SearchProperties[WinWindow.PropertyNames.ClassName] = "ImmersiveLauncher";
            this.WindowTitles.Add("Start menu");
            #endregion
        }

        #region Properties
        public UICalculatorListItem UICalculatorListItem
        {
            get
            {
                if ((this.mUICalculatorListItem == null))
                {
                    this.mUICalculatorListItem = new UICalculatorListItem(this);
                }
                return this.mUICalculatorListItem;
            }
        }
        #endregion

        #region Fields
        private UICalculatorListItem mUICalculatorListItem;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UICalculatorListItem : WinListItem
    {

        public UICalculatorListItem(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinListItem.PropertyNames.Name] = "Calculator";
            this.WindowTitles.Add("Start menu");
            #endregion
        }

        #region Properties
        public WinControl UILogoImage
        {
            get
            {
                if ((this.mUILogoImage == null))
                {
                    this.mUILogoImage = new WinControl(this);
                    #region Search Criteria
                    this.mUILogoImage.SearchProperties[UITestControl.PropertyNames.Name] = "Logo";
                    this.mUILogoImage.SearchProperties[UITestControl.PropertyNames.ControlType] = "Image";
                    this.mUILogoImage.WindowTitles.Add("Start menu");
                    #endregion
                }
                return this.mUILogoImage;
            }
        }
        #endregion

        #region Fields
        private WinControl mUILogoImage;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UICalculatorWindow : WinWindow
    {

        public UICalculatorWindow()
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.Name] = "Calculator";
            this.SearchProperties[WinWindow.PropertyNames.ClassName] = "CalcFrame";
            this.WindowTitles.Add("Calculator");
            #endregion
        }

        #region Properties
        public UIItemWindow1 UIItemWindow
        {
            get
            {
                if ((this.mUIItemWindow == null))
                {
                    this.mUIItemWindow = new UIItemWindow1(this);
                }
                return this.mUIItemWindow;
            }
        }

        public UIItemWindow11 UIItemWindow1
        {
            get
            {
                if ((this.mUIItemWindow1 == null))
                {
                    this.mUIItemWindow1 = new UIItemWindow11(this);
                }
                return this.mUIItemWindow1;
            }
        }

        public UIItemWindow2 UIItemWindow2
        {
            get
            {
                if ((this.mUIItemWindow2 == null))
                {
                    this.mUIItemWindow2 = new UIItemWindow2(this);
                }
                return this.mUIItemWindow2;
            }
        }

        public UIItemWindow3 UIItemWindow3
        {
            get
            {
                if ((this.mUIItemWindow3 == null))
                {
                    this.mUIItemWindow3 = new UIItemWindow3(this);
                }
                return this.mUIItemWindow3;
            }
        }
        #endregion

        #region Fields
        private UIItemWindow1 mUIItemWindow;

        private UIItemWindow11 mUIItemWindow1;

        private UIItemWindow2 mUIItemWindow2;

        private UIItemWindow3 mUIItemWindow3;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIItemWindow1 : WinWindow
    {

        public UIItemWindow1(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ControlId] = "135";
            this.WindowTitles.Add("Calculator");
            #endregion
        }

        #region Properties
        public WinButton UIItem5Button
        {
            get
            {
                if ((this.mUIItem5Button == null))
                {
                    this.mUIItem5Button = new WinButton(this);
                    #region Search Criteria
                    this.mUIItem5Button.SearchProperties[WinButton.PropertyNames.Name] = "5";
                    this.mUIItem5Button.WindowTitles.Add("Calculator");
                    #endregion
                }
                return this.mUIItem5Button;
            }
        }
        #endregion

        #region Fields
        private WinButton mUIItem5Button;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIItemWindow11 : WinWindow
    {

        public UIItemWindow11(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ControlId] = "92";
            this.WindowTitles.Add("Calculator");
            #endregion
        }

        #region Properties
        public WinButton UIMultiplyButton
        {
            get
            {
                if ((this.mUIMultiplyButton == null))
                {
                    this.mUIMultiplyButton = new WinButton(this);
                    #region Search Criteria
                    this.mUIMultiplyButton.SearchProperties[WinButton.PropertyNames.Name] = "Multiply";
                    this.mUIMultiplyButton.WindowTitles.Add("Calculator");
                    #endregion
                }
                return this.mUIMultiplyButton;
            }
        }
        #endregion

        #region Fields
        private WinButton mUIMultiplyButton;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIItemWindow2 : WinWindow
    {

        public UIItemWindow2(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ControlId] = "136";
            this.WindowTitles.Add("Calculator");
            #endregion
        }

        #region Properties
        public WinButton UIItem6Button
        {
            get
            {
                if ((this.mUIItem6Button == null))
                {
                    this.mUIItem6Button = new WinButton(this);
                    #region Search Criteria
                    this.mUIItem6Button.SearchProperties[WinButton.PropertyNames.Name] = "6";
                    this.mUIItem6Button.WindowTitles.Add("Calculator");
                    #endregion
                }
                return this.mUIItem6Button;
            }
        }
        #endregion

        #region Fields
        private WinButton mUIItem6Button;
        #endregion
    }

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UIItemWindow3 : WinWindow
    {

        public UIItemWindow3(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ControlId] = "121";
            this.WindowTitles.Add("Calculator");
            #endregion
        }

        #region Properties
        public WinButton UIEqualsButton
        {
            get
            {
                if ((this.mUIEqualsButton == null))
                {
                    this.mUIEqualsButton = new WinButton(this);
                    #region Search Criteria
                    this.mUIEqualsButton.SearchProperties[WinButton.PropertyNames.Name] = "Equals";
                    this.mUIEqualsButton.WindowTitles.Add("Calculator");
                    #endregion
                }
                return this.mUIEqualsButton;
            }
        }
        #endregion

        #region Fields
        private WinButton mUIEqualsButton;
        #endregion
    }
}

我在onCreate中使用它,如下所示:

private void loadRankOfLeaderBoard(final int level) {
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(_gameHelper.getApiClient(), getResources(). getString(LEADER_BOARDS.get(level-1)), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
        @Override
        public void onResult(Leaderboards.LoadPlayerScoreResult scoreResult) {
            if(isScoreResultValid(scoreResult)){
                rank.add(level-1, (int)scoreResult.getScore().getRank());
                Log.d("COUCOU", "isScoreResultValid "+(level));

            }
            else{
                rank.add(level-1, -1);
                Log.d("COUCOU", "NOTisScoreResultValid "+(level) + " GamesStatusCodes." + (scoreResult.getStatus().getStatusMessage()));

            }
        }
    });     
}
private boolean isScoreResultValid(Leaderboards.LoadPlayerScoreResult scoreResult) {
    return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
}

日志结果是:

GameHelperListener gameHelperListener = new GameHelper.GameHelperListener(){
        @Override
        public void onSignInSucceeded(){
            for(int i = 0; i < LEADER_BOARDS.size(); i++){
                loadRankOfLeaderBoard(i+1);
            }

        }

        @Override
        public void onSignInFailed(){
        }

    };

    _gameHelper.setup(gameHelperListener);

你可以看到,前三个排行榜运作良好,但其他7个排行榜都不行。有时候,10个人中没有人工作。太奇怪了。

谢谢你的帮助!

0 个答案:

没有答案