不运行赛普拉斯和Linux cron

问题描述

希望对您有所帮助。我在Linux上安装了Cypress,并在命令cypress run --record --key *******上手动成功运行了测试

但是,当我将命令写入Cron时,测试无法运行。控制台中没有错误。 Cron正在工作。日期和时间输出等其他命令也可以正常工作。

我这样做了

  1. 创建具有以下内容的 bash-script.sh
#!/bin/bash
cd /home/ubuntu/project-name/cypress
/home/ubuntu/project-name/cypress/node_modules/.bin/cypress run --record --key *****************
  1. 将bash脚本文件放入文件夹/ home / ubuntu /。现在这是脚本/home/ubuntu/bash-script.sh

    的路径
  2. 通过命令'crontab -l'安排了以下命令*/5 * * * * /home/ubuntu/bash-script.sh >> /home/ubuntu/bash-script-log.log

但是计划的命令未执行。日志为空。你能告诉我我在做什么错吗?

解决方法

尝试在bash脚本的开头写入PATH变量。只需执行echo $ PATH;在终端/ bash中,然后将结果复制为PATH变量,如下所示。

让我们首先确保cypress在bash中工作,然后我们将在crontab中触发它。

#!/bin/bash
PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

## Set your cypress folder
yourfullpathtocypressfolder=/home/ubuntu/project-name/cypress;

## Check that we can echo cypress version
$yourfullpathtocypressfolder/node_modules/.bin/cypress -v >> Iamalive.log
  

设置变量 yourfullpathtocypressfolder 后,将脚本另存为myscript.sh。尝试在终端中以bash myscript.sh的身份运行此脚本。

有关使用crontab记录项目的完整代码,如下所示。 确保您已更新cypress.json中的projectID!

您也可以检查要点https://gist.github.com/senniksoft/0e062165fb9121be8d8a0fca4038fbc1

#!/bin/bash
        PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
        
## Set your cypress folder
yourfullpathtocypressfolder=/home/ubuntu/project-name/cypress;
    
## Set your project key
yourprojectkey=xxxxxxxx-c69f-4c44-81c9-xxxxxxxxxxxxx;
    
cd $yourfullpathtocypressfolder;
        
## Example Code to record
./node_modules/.bin/cypress run --record --key $yourprojectkey --spec "cypress/integration/examples/actions.spec.js" >> RecordLog.log

之后,请授予适当的权限,以便crontab可以执行脚本。

chmod +x /home/ubuntu/myscript.sh;

按如下所示将此脚本添加到crontab中

*/5 * * * * bash /home/ubuntu/myscript.sh

运行此脚本后在日志中输出示例。

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    5.1.0                                                                              │
  │ Browser:    Electron 83 (headless)                                                             │
  │ Specs:      1 found (examples/actions.spec.js)                                                 │
  │ Searched:   cypress/integration/examples/actions.spec.js                                       │
  │ Params:     Tag: false,Group: false,Parallel: false                                          │
  │ Run URL:    https://dashboard.cypress.io/projects/2bn65e/runs/2                                │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  examples/actions.spec.js                                                        (1 of 1)
  Estimated: 22 seconds


  Actions
    ✓ .type() - type into a DOM element (7441ms)
    ✓ .focus() - focus on a DOM element (469ms)
    ✓ .blur() - blur off a DOM element (741ms)
    ✓ .clear() - clears an input or textarea element (790ms)
    ✓ .submit() - submit a form (670ms)
    ✓ .click() - click on a DOM element (2705ms)
    ✓ .dblclick() - double click on a DOM element (476ms)
    ✓ .rightclick() - right click on a DOM element (360ms)
    ✓ .check() - check a checkbox or radio element (1114ms)
    ✓ .uncheck() - uncheck a checkbox element (1160ms)
    ✓ .select() - select an option in a <select> element (1068ms)
    ✓ .scrollIntoView() - scroll an element into view (798ms)
    ✓ .trigger() - trigger an event on a DOM element (383ms)
    ✓ cy.scrollTo() - scroll the window or element to a position (2321ms)


  14 passing (24s)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...