Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicks fail when put between multiple measure.start and measure.stop #21

Closed
j940927 opened this issue Oct 21, 2020 · 6 comments
Closed

Comments

@j940927
Copy link

j940927 commented Oct 21, 2020

When putting actions under one measure.start/stop block, the actions work fine, but if seperate these actions into two measure.start/stop blocks, the actions in second block fails. From Chrome dev tool can see it's returning error in console.

Script that works:

    await commands.measure.start('Enter new Page');
    await commands.click.byXpath('//h6[contains(text(),"$$$")]');
    await commands.wait.byXpath('//h3[contains(text(),"$$$")]',60000);
    await commands.wait.byPageToComplete();
    //await commands.measure.stop();

    //await commands.measure.start('Get quote');
    await commands.click.byXpath('//button[contains(text(),"$$$")]');
    await commands.wait.byPageToComplete();
    return commands.measure.stop();

Script that fails:

    await commands.measure.start('Enter new Page');
    await commands.click.byXpath('//h6[contains(text(),"$$$")]');
    await commands.wait.byXpath('//h3[contains(text(),"$$$")]',60000);
    await commands.wait.byPageToComplete();
    await commands.measure.stop();

    await commands.measure.start('Get quote');
    // below click will fail
    await commands.click.byXpath('//button[contains(text(),"$$$")]');
    await commands.wait.byPageToComplete();
    return commands.measure.stop();

Error in Chrome console:
Screen Shot 2020-10-21 at 11 28 32 AM

Versions(Running on Macbook):
Mac OS: darwin 19.0.0 nodejs:12.18.2 sitespeed.io:13.3.2 browsertime:8.14.0 coach:5.0.1 chrome: 86

@j940927
Copy link
Author

j940927 commented Oct 21, 2020

Note: the click that failed won't direct to another page, but it will send some more requests

@soulgalore
Copy link
Member

Hi @j940927 its super hard for me to guess what's going on, can you follow the instructions in https://www.sitespeed.io/documentation/sitespeed.io/bug-report/#explain-how-to-reproduce-your-issue that will make it easier for me so I can reproduce and understand what you try to do.

Thanks!

@j940927
Copy link
Author

j940927 commented Oct 21, 2020

Hi @soulgalore, thanks for your quick response!
Below is the whole script I use, I execute it with command sitespeed.io test.js --multi -n 1

test.js

module.exports = async function(context, commands) {
  
  try {
    //Deleted URL
    await commands.measure.start('','Load home page');

    await commands.measure.start('Enter Secure First Page');
	
    // Open Accident & Other Protections menu and click Secure First link
    await commands.click.byXpath('//a[contains(text(),"Accident & Other Protections")]');
    await commands.click.byXpath('//h6[contains(text(),"Secure First")]');
	
    // Wait for Secure First page header to display
    await commands.wait.byXpath('//h3[contains(text(),"Secure first")]',60000);
    await commands.wait.byPageToComplete();
    await commands.measure.stop();
	

    await commands.measure.start('Get quote for Secure First ');
    // Enter birthday/gender/sum assured details and click get a quote
    await commands.js.run('document.querySelector("input#quote-birthday").value="14-Apr-1996";');
    await commands.click.bySelector('div.section-container section div.btn-female label');
    await commands.addText.bySelector('600000','input[name="sumInsured"]');
    await commands.click.byXpath('//button[contains(text(),"Get a quote")]');
    
    // Wait for quote to display
    await commands.wait.byXpath('//div[contains(@class,"offerPrice")]/span[contains(text(),"150")]',60000);
    await commands.wait.byPageToComplete();
    return commands.measure.stop();


  } catch (e) {
    
    throw e;
  }
};

If script contain first measure.stop(), clicking "Get a Quote" will hit error as screenshot I shared in original post, if I delete first measure.stop(), then the script works fine. Can you please help try if you can reproduce this issue on your side?

@j940927
Copy link
Author

j940927 commented Oct 27, 2020

Hi @soulgalore , I've found the root cause of this issue.

It is due to below code in sitespeed.io\node_modules\coach-core\dist\coach.min.js
for (var t = window.jQuery; t.fn && t.fn.jquery && (t = window.jQuery.noConflict(!0), window.jQuery && window.jQuery.fn) && t.fn.jquery !== window.jQuery.fn.jquery;) e.push(window.jQuery.fn.jquery)

After window.jQuery.noConflict(!0) is executed, $ is no longer referring to jQuery, so when the website used $ to call jQuery, error "$ is not defined" occured.

I've fixed this issue by giving back jQuery to alias "$" after jQuery.noConflict is executed.
var tempForTest = window.$; for(var t=window.jQuery;t.fn&&t.fn.jquery&&(t = window.jQuery.noConflict(!0),window.jQuery&&window.jQuery.fn)&&t.fn.jquery!==window.jQuery.fn.jquery;) e.push(window.jQuery.fn.jquery)} window.$ = tempForTest;

Please advise if this modification would break anything else, thanks!

@soulgalore
Copy link
Member

Thanks @j940927 for looking into this. I'm moving this to the coach and will implement your fix there.

@soulgalore soulgalore transferred this issue from sitespeedio/sitespeed.io Nov 11, 2020
soulgalore added a commit that referenced this issue Nov 11, 2020
@j940927
Copy link
Author

j940927 commented Nov 11, 2020

Thanks! I tried to create a pull request in Coach but didn't succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants