Browser 屏幕分辨率设置不正确

Browser 屏幕分辨率设置不正确,browser,protractor,resolution,Browser,Protractor,Resolution,我试图将浏览器屏幕的分辨率设置为(360640),但当我阅读时,它的值发生了变化,设置值和获取值之间存在差异 resolution(){ browser.manage().window().setSize(360,640); browser.manage().window().getSize().then((getSize) => { console.log('Value of Height', getSize.height);

我试图将浏览器屏幕的分辨率设置为(360640),但当我阅读时,它的值发生了变化,设置值和获取值之间存在差异

 resolution(){
        browser.manage().window().setSize(360,640);
        browser.manage().window().getSize().then((getSize) => {
              console.log('Value of Height', getSize.height);
              console.log('Value of width', getSize.width);
        });
    }
NOTE :: tried with different resolution and their result as below:
1.Width :: 360 and Height :: 640  
Result is coming as Width:: 516 and Height :: 640

2.Width ::768  and Height :: 1024
Result is coming as Width :: 768 and Height :: 788

Using Protractor Version :: Version 5.4.3
      npm :: 6.14.5


Please help me out to solve this problem

您是否可以尝试在功能上设置分辨率,而不是为其创建分辨率函数。像这样:

capabilities: {
        'browserName': 'chrome',
        chromeOptions: {
            args: [ "--headless", "--disable-gpu", "--window-size=1440,960"]
        },
    }
此外,您也可以在onPrepare函数中添加browser.window setSize,如下所示:

onPrepare: async() => {
        browser.baseUrl = 'https://app.thegaas.com';
        await browser.driver.manage().window().setPosition(0,0);
        await browser.driver.manage().window().setSize(1440,960);
        let getSize = await browser.driver.manage().window().getSize();
        console.log('Value of Height', getSize.height);
        console.log('Value of width', getSize.width);
    }

您可以删除async Wait并使用解析承诺。然后改为。

您可以尝试在功能上设置解析,而不是为其创建解析函数吗。像这样:

capabilities: {
        'browserName': 'chrome',
        chromeOptions: {
            args: [ "--headless", "--disable-gpu", "--window-size=1440,960"]
        },
    }
此外,您也可以在onPrepare函数中添加browser.window setSize,如下所示:

onPrepare: async() => {
        browser.baseUrl = 'https://app.thegaas.com';
        await browser.driver.manage().window().setPosition(0,0);
        await browser.driver.manage().window().setSize(1440,960);
        let getSize = await browser.driver.manage().window().getSize();
        console.log('Value of Height', getSize.height);
        console.log('Value of width', getSize.width);
    }

您可以使用删除异步等待并解决承诺。然后改为。

非常感谢Sankalan…它工作正常…但是有没有其他方法可以使用非headless Mode解决此问题您可以从chromeOptions中删除--headless标志。这样不行吗?你想在CI中运行这些吗?嗨,桑卡兰。我试着运行我的测试用例,但没有--无头…问题是可复制的。我可以看到chrome浏览器宽度的差异。它不起作用。我试着在Visual Studio中运行代码嗯,很有趣。您也尝试过onPrepare功能吗?它会给出同样的结果吗?非常感谢Sankalan…它工作得很好…但是有没有其他方法可以解决这个问题,使用无头模式你可以从chromeOptions中删除--headless标志。这样不行吗?你想在CI中运行这些吗?嗨,桑卡兰。我试着运行我的测试用例,但没有--无头…问题是可复制的。我可以看到chrome浏览器宽度的差异。它不起作用。我试着在Visual Studio中运行代码嗯,很有趣。您也尝试过onPrepare功能吗?它会给出同样的结果吗?