简体   繁体   English

试图为主题选择器编写量角器e2e测试

[英]Attempting to write protractor e2e test for theme selector

I am new to Protractor and finding this a little difficult, I hope i can explain it and if you require any further information please let me know. 我是Protractor的新手,发现这有点困难,我希望我能解释一下,如果您需要任何进一步的信息,请告诉我。

So.. The app i am working on has a Default theme set to Black, there is then a drop down you can select in the navbar which gives you an option to select a different theme "White", I have been able to select the White theme successfully but i would like to know how to use this if the default theme were to be white or changed to white and then check that the theme Black is still working how could i write the e2e test to reflect that. 那么..我正在处理的应用程序将默认主题设置为黑色,然后您可以在导航栏中选择一个下拉菜单,它为您提供选择不同主题“白色”的选项,我已经能够选择白色主题成功但我想知道如何使用这个如果默认主题是白色或更改为白色,然后检查主题黑色仍在工作,我怎么能写e2e测试来反映这一点。

I should mention that once a theme is selected it is then cached for 1 year so that theme remains unless changed. 我应该提一下,一旦选择了一个主题,它就会缓存1年,这样主题就会保留,除非改变。

Code i have written to select Light theme 我编写的代码选择Light主题

it('should select theme selector', () => {
         let top = element(by.css('cloudgate-theme-selector'));
         top.element(by.css('.dropdown-toggle')).click();
         element(by.cssContainingText('li a', 'Light')).click();
         browser.sleep(1000);
     });

Thank you for your help in advance. 提前谢谢你的帮助。 cheers, 干杯,

We too Have dark theme and light theme: You probably need to find the value where the themes are stored. 我们也有黑暗主题和浅色主题:您可能需要找到存储主题的值。

In my Project see the below html code: 在我的项目中,请参阅以下HTML代码:

For Dark theme: 对于黑暗主题:

<body class="nsweb-theme-dark">
<nsw-app _nghost-ewh-1=""><toaster-container _ngcontent-ewh-1="" ng-reflect-toasterconfig="[object Object]">

For Light Theme: 对于轻主题:

<body class="nsweb-theme-light">
<nsw-app _nghost-ewh-1=""><toaster-container _ngcontent-ewh-1="" ng-reflect-toasterconfig="[object Object]">

SO you can just Take the text where theme data(For me it is class) is available ie light/dark and then validate it with: 所以,您可以只获取主题数据(对我来说是类)可用的文本,即亮/暗,然后使用以下命令验证:

if (theme == dark)
  {
   expect(themecolor).toBe("nsweb-theme-dark")
  }
else 
  {
   expect(themecolor).toBe("nsweb-theme-light")
  }

Hope you are clear. 希望你清楚。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM