量角器中的forEach()循环测试语言变化

时间:2018-03-13 18:57:43

标签: typescript foreach protractor

如何在页面对象模型中格式化以下代码以循环浏览网页上的所有可用显示语言:

页面对象中的

languageBulgarian = element(by.css('.vm-language-choices > li:nth-child(1)'));
loginButtonTextBulgarian = 'XXX';
aboutTextBulgarian = 'XXX';
languageCzech = element(by.css('.vm-language-choices > li:nth-child(2)'));
loginButtonTextCzech = 'Prihlaseni';
aboutTextCzech = 'O';
languageDanish = element(by.css('.vm-language-choices > li:nth-child(3)'));
loginButtonTextDanish = 'Log ind';
aboutTextDanish = 'Om';

等...

在spec文件中,我正在测试:

it('should change the language to Czech when selected from the language drop-down', () => {
  loginPage.clickLanguageDropdown();
  loginPage.languageCzech.click();
  loginPage.waitForElementText(loginPage.loginButton, loginPage.loginButtonTextCzech);
  loginPage.waitForElementText(loginPage.aboutHeader, loginPage.aboutTextCzech);
  expect(loginPage.loginButton.getText()).toEqual(loginPage.loginButtonTextCzech);
  expect(loginPage.aboutHeader.getText()).toEqual(loginPage.aboutTextCzech);
});

我想将此函数移动到页面对象辅助函数中,并使用forEach遍历数组中的语言。我真是太新了,我不知道怎么做......

1 个答案:

答案 0 :(得分:1)

您可以将所有语言和预期文本存储为数组中的对象。然后使用forEach迭代数组。由于public class TableListView extends AppCompatActivity { DBHelper dbHelper = new DBHelper(this); RecyclerView mRecyclerView; private static RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; LinearLayout firstLL; LinearLayout mainLL; TextView tvNoData; static final int READ_BLOCK_SIZE = 100; static String stringREAD; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_table_list_view); setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); firstLL = findViewById(R.id.firstLL); mainLL = findViewById(R.id.mainLL); tvNoData = findViewById(R.id.tvNoData); readFROM_TEXT_FILE(); dbHelper = new DBHelper(this); List<TableModel> dbTTList; dbTTList = dbHelper.getDataFrom_TABLE_TRACKER(); int sz = dbTTList.size(); if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz == 0){ System.out.println("################ SIZE top "+sz); tvNoData.setVisibility(View.VISIBLE); tvNoData.setText("No Data Found\n\nClick On Manage Tables"); mRecyclerView = findViewById(R.id.recycleview); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new TableTrackerAdapter(this,dbTTList); mRecyclerView.setAdapter(mAdapter); } if(stringREAD.equals("EXTERNAL") || stringREAD.equals("INTERNAL") && sz > 0){ System.out.println("################ SIZE bot "+sz); mRecyclerView = findViewById(R.id.recycleview); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new TableTrackerAdapter(this,dbTTList); mRecyclerView.setAdapter(mAdapter); tvNoData.setVisibility(View.INVISIBLE); } setTitle("");// This sets the title of the toolbar Toolbar topToolBar = findViewById(R.id.toolbar); setSupportActionBar(topToolBar); addListenerOnButtonAdd(); if (Build.VERSION.SDK_INT >= 23) { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { } else { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 666); // Comment 26 } } }// END onCreate 元素只会改变第n个子节点的数量,因此可以使用数组索引,甚至不需要存储任何其他页面对象。

languageBulgarian